Posts

Parallel Execution using TestNG

For Parallel execution ,we will be working on 3 different components as below: A Factory class that will create WebDriver instances  A Manager class that can be accessed to retrieve a WebDriver instance A TestNG listener that will be responsible for instantiating the WebDriver instance automatically First we will create a Factory class which will create and return the desired webdriver object: package execution.parallel; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; class LocalDriverFactory {      static WebDriver createInstance(String browserName) {          WebDriver driver = null ;          if (browserName.toLowerCase().contains( "firefox" )) {...

Verifying ToolTip Using Selenium webdriver

public String GetToolTipText() throws InterruptedException{    builder.clickAndHold(driver.findElement(By.className("locator here"))).build().perform();    Thread.sleep(2000);    return driver.findElement(By.xpath("locator of tooltip")).getText();  }

Selenium - How to switch to Web Dialog window & back to Parent Browser Window

Steps are as follows -            1.    Before clicking the link, get the handle id of the browser window.                  String BrowserParent = driver.getWindowHandle();            2.  After clicking the link;                  String str = driver.getWindowHandle();                  driver.switchTo().window(st); // switch to child browser            3.      Once the operation on the web dialog box is completed.                        driver.switchTo().window(BrowserParent);

Web Driver Interface Implementations

WebDriver is an interface to use for testing which represents web browser. Following is list of classes which implements WebDriver interface: 1.       AndroidDriver 2.       AndroidWebDriver 3.       ChromeDriver 4.       EventFiringWebDriver 5.       FirefoxDriver 6.       HtmlUnitDriver 7.       InternetExplorerDriver 8.       IPhoneDriver 9.       IPhoneSimulatorDriver 10.     RemoteWebDriver 11.     SafariDriver

How To Create Runnable Jar File in Selenium

   1.    Right click on your project in eclipse    2.    Select Export    3.   Select [Java -> Runnable Jar file]    4.   Provide Export Location    5.   Click finish   Run generated .jar file from command prompt Script will run on machine having desired Browser & Java.

Selenium WebDriver: How to Handle Ajax Application

A common problem we face during automation using selenium  WebDriver is to handle the ajax calls. It is difficult to know when the call is complete and page has been updated. There are several ways to handle the ajax calls. This blog describes them one by one. We can handle Ajax calls in two ways:   Hard Wait - this is most commonly used method but not recommended while doing the automation. Only in some exceptional cases use or for short time use it ·      JAVA: Use java method Thread.Sleep( ) to suspend execution for specified time. Syntax – Thread.sleep(1000) // time unit is millisecond ·     Implicit Wait – An implicit wait is to tell WebDriver to stop the DOM for a certain amount of time. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. Syntax – driver.manage().timeouts().Implicitly Wait(10, TimeUnit.SECONDS);   // Time is in   secon...

Selenium: How to handle Stale Element Exception error

Common Causes A stale element reference exception is thrown in one of two cases: The element has been deleted entirely or element/page  has been refreshed The element is no longer attached to the DOM. Solution The most simple solution is to use the Java PageFactory, this will create a proxy WebElement that will  find the element every time you use it (There is a slim change that the element will be released in the  couple of milliseconds between it being found and you performing an action on it, in this case it is  suggested to use an explicit wait to wait for the element to become stale before finding it again). Use try catch to handle this exception and reload the element in catch block. Add a short sleep between FindElement & action method. .