All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sunnydsouza.testframework.layers.selenium.actions.SeleniumWebdriver Maven / Gradle / Ivy

Go to download

Generic frameowrk with different standalone layers for reporting,logging,test execution and test data management.

There is a newer version: 3.1.2
Show newest version
package com.sunnydsouza.testframework.layers.selenium.actions;


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.sunnydsouza.testframework.layers.execution.FrameworkException;
import com.sunnydsouza.testframework.layers.logging.FrameworkLogger;
import com.sunnydsouza.testframework.utilities.testutilities;

import cucumber.api.Scenario;


public class SeleniumWebdriver {

	protected WebDriver driver;
	//public Logger logger = Logger.getLogger(SeleniumWebdriver.class);
	private FrameworkLogger selActionlog=new FrameworkLogger(SeleniumWebdriver.class) ;
	protected static final int WEBTABLE_SEARCH_OPTION_EQUALS=0;
	protected static final int WEBTABLE_SEARCH_OPTION_CONTAINS=1;
	
	protected static final Map SELENIUM_WEBDRIVER_OPTIONS = new HashMap<>();
	
	public SeleniumWebdriver(){
		//this.driver=driver;
	}
	
	
	  public SeleniumWebdriver(WebDriver driver){ 
		  this.driver=driver;
		  //selActionlog=new FrameworkLogger(this.getClass());
	  }
	  
	 /* public SeleniumWebdriver(WebDriver driver,FrameworkLogger logger){ 
		  this.driver=driver;
		  this.logger=logger;
		  this.logger.getLogger(SeleniumWebdriver.class);
	  }*/
	 
	
	protected WebDriver getDriver() {
		return this.driver;
	}
	
	protected String getPageTitle(){
		return driver.getTitle();
	}
	
	protected String getPageCode(){
		return driver.getPageSource();
	}
	
	protected void setDefaultOptions(){
		SELENIUM_WEBDRIVER_OPTIONS.put("WEBTABLE_SEARCH_OPTION", WEBTABLE_SEARCH_OPTION_EQUALS);
	}
	
	
	protected void setImplicitWait(int timeout){
		driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
	}
	
	protected void setPageLoadTimeout(int timeout){
		driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
	}
	
	protected void setScriptTimeout(int timeout){
		driver.manage().timeouts().setScriptTimeout(timeout, TimeUnit.SECONDS);
	}
	
	
	protected void setExplicitWait(WebElement element,int timeout){
		//WebElement element = null;
		new WebDriverWait(driver,timeout).until(ExpectedConditions.visibilityOf(element));
//		element.click();
//		element.sendKeys("234324");
		
	}
	
	//opens a new driver session browser and navigates to the supplied pageURL
	protected void navigateToPage(WebDriver driver,String pageURL){
		driver.get(pageURL);
		selActionlog.debug("Successfully opened the browser and navigated to page:"+pageURL);
	}
	
	protected void navigateToPage(String pageURL){
		driver.get(pageURL);
		selActionlog.debug("Successfully opened the browser and navigated to page:"+pageURL);
	}
	
	
	//navigate to a new url in existing driver session
	protected void navigate(String pageURL){
		driver.navigate().to(pageURL);
		selActionlog.debug("Successfully navigated to page:"+pageURL);
	}
	
	protected void refresh(){
		driver.navigate().refresh();
		selActionlog.debug("Successfully refreshed the page");
	}
	
	protected void navigateToBackPage(){
		driver.navigate().back();
		selActionlog.debug("Successfully navigated to page<-back");
	}
	
	protected void navigateToForwardPage(){
		driver.navigate().forward();
		selActionlog.debug("Successfully navigated to page->forward");
	}
	
	protected boolean isElementExists(WebDriver driver,By elementIdentifier){
		List eI=driver.findElements(elementIdentifier);
		if(eI.size()>0) {
			System.out.println(elementIdentifier.toString()+" : Element exists");
			
			selActionlog.debug(elementIdentifier.toString()+" : Element exists");
			selActionlog.debug(elementIdentifier.toString()+" : "+eI.size()+" elements with identifier found");
			return true;
		}	
		return false;
		
	}
	
	/* Overloaded function */
	protected boolean isElementExists(WebElement element){
		
		if(element.isDisplayed()) {
			System.out.println(element.toString()+" : Element is visible");
			selActionlog.debug(element.toString()+" : Element is visible");
			
			return true;
		}	
		return false;
		
	}
	
	

	protected static WebElement findObject(WebDriver driver, By wb) {
		try {
			return driver.findElement(wb);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	// guided by timeouts
	protected boolean waitTillElementExists(WebDriver driver, WebElement wb) {
		return false;

	}

	protected String readText(WebDriver driver, By wb) {
		if (isElementExists(driver, wb)) {
			
			return driver.findElement(wb).getText();
		}
		return null;
	}

	protected void writeText(WebDriver driver, By wb,String text) {
		if (isElementExists(driver, wb)) {
			driver.findElement(wb).sendKeys(text);
		}
		
	}

	protected void clickLink(WebDriver driver, By wb) {
		if (isElementExists(driver, wb)) {
			driver.findElement(wb).click();
		}
		
	}
	
	/*  Overloaded function */
	protected String readText(WebElement element) {
		
		if (isElementExists(element)) {
			selActionlog.debug("Attempting to read the text from element "+element.toString());
			return element.getText();
		}
		return null;
	}

	/*  Overloaded function */
	protected void writeText(WebElement element,String text) {
		//if (isElementExists(driver, wb)) {
			element.sendKeys(text);
			selActionlog.debug("Attempting to write the text '"+text+"' to element "+element.toString());
		//}
		
	}

	/*  Overloaded function */
	protected void clickLink(WebElement element) {
		//if (isElementExists(driver, wb)) {
		try{
			selActionlog.info("Clicking on the link: "+element.toString());
			element.click();
			//logger.info("Clicked on the link: "+element.toString());
		}
		catch(Exception e){
			throw new FrameworkException("Failed to click on element ->"+element.toString()+e.getMessage());
		}
			
		//}
		
	}
	
	//Anything thats not a link. Just for esthetics purposes.
	protected void clickElement(WebElement element) {
		//if (isElementExists(driver, wb)) {
			element.click();
		//}
		
	}
	
	protected WebElement buildElement(WebElement baseElement,By selector) {
		//if (isElementExists(driver, wb)) {
		try {
			return baseElement.findElement(selector);
		}
		catch(Exception e){
			throw new FrameworkException("Failed to build element using selector ->"+selector.toString()+e.getMessage());
		}
		//}
		
	}
	
	protected List buildElements(WebElement baseElement,By selector) {
		//if (isElementExists(driver, wb)) {
		try {
			return baseElement.findElements(selector);
		}
		catch(Exception e){
				throw new FrameworkException("Failed to build element using selector ->"+selector.toString()+e.getMessage());
			}	
		//}
		
	}
	
	protected void selectMultipleDropdown(WebElement element,String[] options) {
		// TODO Auto-generated method stub for selectMultipleDropdown
		Select select=new Select(element);
		try {
			for(String optionToSelect:options){
				select.selectByVisibleText(optionToSelect);
			}
		}
		catch(Exception e){
			throw new FrameworkException("Unable to select options "+options.toString()+e.getMessage());
		}
		
	}
	
	protected void selectRadioOption(WebElement element){
		// one can give directly the webelement of the radio button to be clicked
		element.click();
	}
	
	protected void selectRadioOption(List elements,String optionVal){
		// select the radio button based on the value paramter
		for(WebElement individualOption:elements){
			if(this.getAttribute(individualOption,"value").equals(optionVal)){
				this.clickElement(individualOption);
			}
		}
	}
	
	protected String getSelectedRadioOptionValue(List elements){
		// TODO Auto-generated method stub for getSelectedRadioOptionValue
		String selVal=null;
		for(WebElement individualOption:elements){
			if(individualOption.isSelected()){
				selVal= individualOption.getAttribute("value");
			}
		}
		
		return selVal;
		
	}
	
	protected String getSelectedRadioOptionText(List elements){
		// TODO Auto-generated method stub for getSelectedRadioOptionValue
		String selText=null;
		for(WebElement individualOption:elements){
			if(individualOption.isSelected()){
				selText=individualOption.getText();
			}
		}
		
		return selText;
	}
	
	protected void getRadioOptions(WebElement element){
		// TODO Auto-generated method stub for getRadioOptions
	}
	
	/*public void getCheckboxOptions(WebElement element){
		// TODO Auto-generated method stub for getCheckboxOptions
	}*/
	
	protected void setCheckboxOption(WebElement element, Boolean checkFlag) {
		// TODO Auto-generated method stub
		if(element.isSelected() && checkFlag==false){
			element.click();
		}
		else if(!element.isSelected() && checkFlag==true){
			element.click();
		}
		
	}
	
	protected String getAttribute(WebElement element,String attribute) {
		// TODO Auto-generated method stub for getAttribute
		try {
			return element.getAttribute(attribute);
		}
		catch(Exception e) {
			throw new RuntimeException("Unable to fetch the attribute "+attribute+" for WebElement "+element.toString());
		}
		
	}
	
	
	protected boolean verifyText(WebDriver driver,WebElement target,String expectedText){
		
		// TODO Auto-generated method stub for verifyText
		return false;
		
		
		
	}
	
	
	protected boolean verifyTrue(){
	
		// TODO Auto-generated method stub for verifyTrue
		return false;
		
		
		
	}
	
	protected boolean verifyFalse(){
		// TODO Auto-generated method stub for verifyFalse
		
		return false;
		
		
		
	}
	
	
	
	

/*	public static void mouseHoverByXpath(WebDriver driver,String strValue1, String strValue2)
	{
		try
		{
			WebElement element1 = null;
			element1 = WD.findObject(driver,"By.xpath",strValue1);
			Actions action = new Actions(driver);
			action.moveToElement(element1);
			action.perform();
			WebElement element2 = null;
			element2 = WD.findObject(driver,"By.xpath",strValue2);
			action.moveToElement(element2);
			action.perform();
			action.click();
			action.perform();
		}
		catch (Exception e) 
		{
			logger.fatal("Error in MouseHover.byXpath " + e.getMessage());
		}		
	}
*/	
	protected void doActions(String actionToBePerformed,WebDriver driver) {
		//String ab= "ewrwe";
		Actions a=new Actions(driver);
		
		//actionToBePerformed - could be enum
		
		switch(actionToBePerformed){
			case "click":
				
			case "dragNdrop":
				
		}
		
	}
	
	protected void doMouseHover(WebElement target) {
		Actions a=new Actions(driver);
		a.moveToElement(target)
			.build()
			.perform();
	}
	
	protected void doClickAction(WebDriver driver,WebElement target){
		Actions a=new Actions(driver);
		a.click(target)
			.build()
			.perform();
	}
	
	protected void doMoveAndClickAction(WebDriver driver,WebElement target){
		Actions a=new Actions(driver);
		a.moveToElement(target)
			.click()
			.build()
			.perform();
	}
	
	protected void doDragAndDropAction(WebDriver driver,WebElement source,WebElement target){
		Actions a=new Actions(driver);
		a.clickAndHold(source)
			.moveToElement(target)
			.release()
			.build()
			.perform();
	}

	protected void selectDropdown(WebDriver driver, By wb, String value) {
		try
		{		
			
			if (isElementExists(driver, wb)) {
				Select select = new Select(driver.findElement(wb));
				select.selectByVisibleText(value);
				
			}
			
		}
		catch (Exception e) 
		{
			selActionlog.fatal("Error in IsObjectPresent.byId " + e.getMessage());
		}	
	}
	
	
	
	protected boolean verifySelectedDropdown(WebElement element,String expSelectedOption) {
		//convert the single expected option into a list
		List expSelectedOptions=new ArrayList<>();
		expSelectedOptions.add(expSelectedOption);
		return verifySelectedDropdown(element,expSelectedOptions);
	}
	
	protected boolean verifySelectedDropdown(WebElement element,List expSelectedOptions) {
		Select selectDropdown=new Select(element);
		//List selectedOptionElements=selectDropdown.getAllSelectedOptions();
		List selectedOptions=new ArrayList<>();
		for(WebElement eachOption:selectDropdown.getAllSelectedOptions()){
			selectedOptions.add(eachOption.getText());
		}
		selectedOptions.removeAll(expSelectedOptions);
		if(selectedOptions.size()>0)
			return false;
		else
			return true;
	}
		
	
	
	protected void selectDropdown(WebElement element, String value) {
		selectDropdown(element, value, true);
	}

	/* Overloaded function */
	protected void selectDropdown(WebElement element, String value,boolean strictCheck) {
		try
		{		
			if (isElementExists(element)) {
				Select select = new Select(element);
				if(strictCheck==true) {
					
					select.selectByVisibleText(value);
				}
				else if(strictCheck=false) {
					List allOptions=select.getOptions();
					Iterator optionIterator=allOptions.iterator();
					while(optionIterator.hasNext()){
						WebElement option=optionIterator.next();
						if(option.getText().contains(value)){
							select.selectByValue(option.getAttribute("value"));
						}
					}
				}
			}
		}
		catch (Exception e) 
		{
			selActionlog.error("Error in selecting the required option :" +value+" error : "+ e.getMessage());
		}	
	}
	
	protected void selectDropdown(WebElement element, int index) {
		try
		{		
			if (isElementExists(element)) {
				Select select = new Select(element);
				select.selectByIndex(index);
			}
		}
		catch (Exception e) 
		{
			selActionlog.fatal("Error in IsObjectPresent.byId " + e.getMessage());
		}	
	}
	
	
	protected void deselectDropdown(WebElement element, int index) {
		try
		{		
			if (isElementExists(element)) {
				Select select = new Select(element);
				select.deselectByIndex(index);
			}
		}
		catch (Exception e) 
		{
			selActionlog.fatal("Error in IsObjectPresent.byId " + e.getMessage());
		}	
	}
	
	protected void deselectDropdown(WebElement element, String value) {
		try
		{		
			if (isElementExists(element)) {
				Select select = new Select(element);
				select.deselectByVisibleText(value);
			}
		}
		catch (Exception e) 
		{
			selActionlog.fatal("Error in IsObjectPresent.byId " + e.getMessage());
		}	
	}

	
	
	//****** WebTable operations *///////////
	
	/*
	public int getWebTableRowsCount(){
		
	}
	
	public int getWebTableColumnsCount(){
		
	}
	
	public int getWebTableCellValue(){
		
	}
	
	
	public boolean isValuePresentInWebTable(WebDriver driver, By webTable,String conditions){
		
	}
	
	*/
	
	protected SeleniumWebdriver setWebtableSearchOption(int option){
		SELENIUM_WEBDRIVER_OPTIONS.put("WEBTABLE_SEARCH_OPTION", option);
		return this;
	}
	protected String isValuePresentInWebTable(WebDriver driver, By webTable,int searchCol, String searchStr,int retCol){
		WebElement webTbl=driver.findElement(webTable);
		List rows=webTbl.findElements(By.tagName("tr"));
		
		Iterator rowIterator=rows.iterator();
		while(rowIterator.hasNext()){
			WebElement cols=rowIterator.next().findElement(By.xpath("//td["+String.valueOf(searchCol)+"]"));
			
			if(SELENIUM_WEBDRIVER_OPTIONS.containsKey("WEBTABLE_SEARCH_OPTION")){
				if((int)SELENIUM_WEBDRIVER_OPTIONS.get("WEBTABLE_SEARCH_OPTION")==WEBTABLE_SEARCH_OPTION_EQUALS){
					if(cols.getText().equals(searchStr)){
						return cols.findElement(By.xpath("//td["+String.valueOf(retCol)+"]")).getText();
					}
				}
				else if((int)SELENIUM_WEBDRIVER_OPTIONS.get("WEBTABLE_SEARCH_OPTION")==WEBTABLE_SEARCH_OPTION_CONTAINS){
					if(cols.getText().contains(searchStr)){
						return cols.findElement(By.xpath("//td["+String.valueOf(retCol)+"]")).getText();
					}
				}
			}
			else {
				if(cols.getText().contains(searchStr)){
					return cols.findElement(By.xpath("//td["+String.valueOf(retCol)+"]")).getText();
				}
			}
		}
		return null;
		
	}
	
	protected String returnRowMatchingCondition(WebDriver driver, By webTable,int searchCol, String searchStr,int retCol){
		return null;
	}
	
	
	//returns the Frameno
	protected int findFrameContainingWebElement(WebDriver driver, By wb) {
		List frameList=driver.findElements(By.tagName("iframe"));
		System.out.println(frameList.size());
		
		return 0;
	}

	//returns the Windowno
	protected int findWindowContainingWebElement() {
		
		 String parentHandle = driver.getWindowHandle();
		 for (String windowHandle:driver.getWindowHandles() ) {
			 driver.switchTo().window(windowHandle);
		 
		 }
		return 0;
	}

	/*
	public void findElement() {

	}*/

	protected void switchAlert() {
		driver.switchTo().alert();
	}
	
	protected void switchAlertAndAccept() {
		driver.switchTo().alert().accept();
	}
	
	
	protected void switchAlertAndDismiss(int frameno) {
		driver.switchTo().alert().dismiss();
	}
	
	protected boolean isAlertPresent() {

	  boolean presentFlag = false;

	  try {

		   // Check the presence of alert
		   Alert alert = driver.switchTo().alert();
		   // Alert present; set the flag
		   presentFlag = true;
		   // if present consume the alert
		   alert.accept();

	  } catch (NoAlertPresentException ex) {
		   
	  }
	  
	  return presentFlag;
	}	  
	
	protected void switchFrame(int frameno) {
		driver.switchTo().frame(frameno);
	}
	
	protected void switchFrame(String framename) {
		driver.switchTo().frame(framename);
	}
	
	protected void switchToParentFrame() {
		driver.switchTo().parentFrame();
	}
	
	protected void switchToDefaultContent() {
		driver.switchTo().defaultContent();
	}
	
	protected String getCurrentWindowHandle(){
		return driver.getWindowHandle();
	}
	
	protected void switchToLastWindow(){
		//String parentHandle = driver.getWindowHandle();
		for (String windowHandle:driver.getWindowHandles() ) {
			 driver.switchTo().window(windowHandle);
		 }
	}
	
	protected boolean switchToWindowContainingText(String windowName,String expWindowTitle){
		for (String windowHandle:driver.getWindowHandles() ) {
			driver.switchTo().window(windowHandle);
			if(driver.getTitle().contains(expWindowTitle)) {
				return true;
			}
			else
				return false;
		}
		return false;
		
	}
	
	protected void switchToWindow(String windowName){
		driver.switchTo().window(windowName);
	}
	
	protected boolean switchToWindow(String windowName,String expWindowTitle){
		driver.switchTo().window(windowName);
		if(driver.getTitle().contains(expWindowTitle)) {
			return true;
		}
		else
			return false;
	}
	
	//To capture Screen Shot
	/*public static void captureScreen(WebDriver driver, String fileName) 
	{	
		try
		{
		    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
		    FileUtils.copyFile(scrFile, new File(fileName));
		    wait(5);
		}
		catch(Exception e)
		{
			logger.severe("Error while capturing screen shot " + e.getMessage());
		}
	}*/
	
	/** DEPRECATED - after binding the webdriver instance with the instance of this class
	 * Logger function to log the output to the final ExtentReport
	 * @param driver
	 * @param takeScreenshot
	 * @param stepDesc
	 * @param reporter
	 
	public void log(WebDriver driver, TakeScreenshot takeScreenshot,String stepDesc,ExtentTest reporter){
		
		
		if(takeScreenshot.equals(TakeScreenshot.YES))
			reporter.log(LogStatus.PASS, stepDesc+"Snapshot below: " + reporter.addScreenCapture(captureScreen(driver,testutilities.currentTimeStamp())));
		else
			reporter.log(LogStatus.PASS, stepDesc);
	}
	*/
	
	
	
	/** Logger function to log the output to the final ExtentReport
	 * 
	 * @param takeScreenshot
	 * @param stepDesc
	 * @param reporter
	 * @throws IOException 
	 */
	/*public void report(TakeScreenshot takeScreenshot,String stepDesc,Object reporter) {
		
		if(reporter instanceof ExtentTest) {
			if(takeScreenshot.equals(TakeScreenshot.YES))
				try {
					//((ExtentTest)reporter).pass(stepDesc+" Snapshot below: " + ((ExtentTest)reporter).addScreenCaptureFromPath(GetScreenShot.capture(driver,GlobalConfig.REPORTING_DIR+"/"+((ExtentTest)reporter).getModel().getName())));
					//MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build()
					((ExtentTest)reporter).pass(stepDesc,MediaEntityBuilder.createScreenCaptureFromPath(GetScreenShot.capture(driver,GlobalConfiguration.REPORTING_DIR+"/"+((ExtentTest)reporter).getModel().getName())).build());
					
				}
				catch(IOException io){
					io.printStackTrace();
				}
			else
				((ExtentTest)reporter).log(Status.PASS, stepDesc);
		}
		else if(reporter instanceof Scenario) {
			if(takeScreenshot.equals(TakeScreenshot.YES)) {
				((Scenario)reporter).write(stepDesc);
				captureScreenWithCucumber(driver,(Scenario)reporter);
			}
			else
				((Scenario)reporter).write(stepDesc);
		}
	}*/
	
	/** Captures screenshot using selenium and saves the same with current timestamp
	 * 
	 * @param screenShotDir
	 * @return
	 */
	protected String captureScreen(String screenShotDir) 
	    {
	        TakesScreenshot ts = (TakesScreenshot)driver;
	        File source = ts.getScreenshotAs(OutputType.FILE);
	        String dest = System.getProperty("user.dir") +"\\ExtentReports\\"+screenShotDir+"\\"+testutilities.currentTimeStamp()+".png";
	        File destination = new File(dest);
	        try {
				FileUtils.copyFile(source, destination);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}        
	                     
	        return dest;
	    }
	
	
	protected String captureScreen(String screenShotDir,String screenShotName) 
	    {
	        TakesScreenshot ts = (TakesScreenshot)driver;
	        File source = ts.getScreenshotAs(OutputType.FILE);
	        String dest = System.getProperty("user.dir") +"\\"+screenShotDir+"\\"+screenShotName+".png";
	        File destination = new File(dest);
	        try {
				FileUtils.copyFile(source, destination);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}        
	                     
	        return dest;
	    }
	
	 
	protected void captureScreenWithCucumber(WebDriver driver,Scenario logger){
		try{
			final byte[] screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
			logger.embed(screenshot, "image/png"); //stick it in the report	
		}catch(Exception e){
			System.out.println(e.getMessage());
			}
	} 
	 

	
	/**
     * Wait for page to load. 
     */		
	/*
	public static void waitForPage(WebDriver driver, String strBy, String strValue)
	{
		try
		{		
			WebDriverWait wait = new WebDriverWait(driver,120);
			if(strBy.equals("By.id"))
				wait.until(ExpectedConditions.elementToBeClickable(By.id(strValue)));
			else if(strBy.equals("By.className"))
				wait.until(ExpectedConditions.elementToBeClickable(By.className(strValue)));
			else if(strBy.equals("By.tagName"))
				wait.until(ExpectedConditions.elementToBeClickable(By.tagName(strValue)));
			else if(strBy.equals("By.name"))
				wait.until(ExpectedConditions.elementToBeClickable(By.name(strValue)));
			else if(strBy.equals("By.linkText"))
				wait.until(ExpectedConditions.elementToBeClickable(By.linkText(strValue)));
			else if(strBy.equals("By.partialLinkText"))
				wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText(strValue)));
			else if(strBy.equals("By.cssSelector"))
				wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(strValue)));
			else if(strBy.equals("By.xpath"))
				wait.until(ExpectedConditions.elementToBeClickable(By.xpath(strValue)));			
			wait(2);
		}
		catch (Exception e) 
		{
			logger.fatal("Error in WD.waitForPage " + e.getMessage());
		}	
	}
	*/
	
	
	/**
     * Wait for page to load. 
     */		
	protected void waitForPage(WebDriver driver, By wb)
	{
		try
		{		
			WebDriverWait wait = new WebDriverWait(driver,120);
			wait.until(ExpectedConditions.elementToBeClickable(wb));
			
			/*
			if(strBy.equals("By.id"))
				wait.until(ExpectedConditions.elementToBeClickable(By.id(strValue)));
			else if(strBy.equals("By.className"))
				wait.until(ExpectedConditions.elementToBeClickable(By.className(strValue)));
			else if(strBy.equals("By.tagName"))
				wait.until(ExpectedConditions.elementToBeClickable(By.tagName(strValue)));
			else if(strBy.equals("By.name"))
				wait.until(ExpectedConditions.elementToBeClickable(By.name(strValue)));
			else if(strBy.equals("By.linkText"))
				wait.until(ExpectedConditions.elementToBeClickable(By.linkText(strValue)));
			else if(strBy.equals("By.partialLinkText"))
				wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText(strValue)));
			else if(strBy.equals("By.cssSelector"))
				wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(strValue)));
			else if(strBy.equals("By.xpath"))
				wait.until(ExpectedConditions.elementToBeClickable(By.xpath(strValue)));			
			*/
			//wait(2);
		}
		catch (Exception e) 
		{
			selActionlog.fatal("Error in WD.waitForPage " + e.getMessage());
		}	
	}
	
	
    /**
     * Wait till timeOut Seconds. 
     * Arguments: 
     * 1. timeOut: Seconds to wait.
     */		
	protected  void wait(int timeOut)
	{
		try
		{		
			int count =0;
			while(true)
			{
				if (count < timeOut)
				{
					try
					{
						// Sleep at least n milliseconds. 1 millisecond = 1/1000 of a second.
						//Thread.sleep(MIN_WAIT_TIME_IN_MS);
						Thread.sleep(5000);
						count++;
					}
					catch (InterruptedException e )
					{
						selActionlog.fatal("Thread Interrupted !!!");
					}
				}
				else
					break;
			}
		}
		catch (Exception e) 
		{
			//logger.fatal("Error in WD.wait " + e.getMessage());
		}	
	}	
    /**
     * Close the browser. 
     */		
	protected static void closeBrowser(WebDriver driver)
	{
		try
		{		
			driver.quit();
		}
		catch (Exception e) 
		{
			//logger.fatal("Error in WD.closeBrowser " + e.getMessage());
		}	
	}
}


final class Result 
{   
	//final class
	//private Result() {} //private constructor
	public static final String PASS = "PASS";
	public static final String FAIL = "FAIL";
	public static final String WARNING = "WARNING";
	public static final String ERROR = "ERROR";
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy