Posts

Showing posts from 2013

My Research on Cucumber

Introduction# Cucumber is a functional test automation tool for lean and agile teams. It supports behaviour-driven development, specification by example and agile acceptance testing.The language that Cucumber understands is called Gherkin. You can use it to automate functional validation in a form that is easily readable and understandable to business users, developers and testers. This helps teams create executable specifications, that are a goal for development, acceptance criteria and functional regression checks for future changes. In this way, Cucumber allows teams to create living documentation, a single authoritative source of information on system functionality that is always up-to-date.   AN EXAMPLE: Feature: Search courses   In order to ensure better utilization of courses   Potential students should be able to search for courses   Scenario: Search by topic     Given there are 240 courses which do not have the topic "biology"     And

Selenium :- How to Open Chrome Browser

import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class chrome1 {  public static void main(String[] args)  {   System.setProperty("webdriver.chrome.driver","C:\\Chrome\\chromedriver.exe"); //path of        chromeDriver.exe file   WebDriver driver = new ChromeDriver();   driver.get("http://google.com");  } }             

TestNG vs. JUnit4

Image
 TestNG vs. JUnit4 JUnit 4 and TestNG are both very popular unit test framework in Java. Both frameworks look very similar in functionality. Which one is better? Which unit test framework should one choose in Java project? Here is the quick snapshot of features comparison:

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" )) {              driver = new FirefoxDriver();              return driver;          }  

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   seconds or we can also change Unit in second argument

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. .

Performing Mouse Hover Using selenium Webdriver

Sometimes its not really possible to perform a 'mouse hover' action, instead you need to chain all of the actions that you want to achieve in one go. So move to the element that reveals the others, then during the same chain, move to the now revealed element and click on it. When using Action Chains you have to remember to 'do it like a user would'. /********************************************************************   Actions action = new Actions ( webdriver );   WebElement we = webdriver . findElement ( By . xpath ( "xpath here" ));     action . moveToElement ( we ). moveToElement ( webdriver . findElement ( By . xpath ( "/expression-here" ))). click (). build (). perform ();   ************************************************************************/

Selenium WebDriver : How to Handle JavaScript Alerts and Prompts

Selenium 2 provides Alerts API, to work on pop & alert window – // Get a handle to the open alert, prompt or confirmation Alert alert = driver.switchTo().alert(); // Get the text of the alert or prompt alert.getText(); // And acknowledge the alert (equivalent to clicking “OK”)

Setting up Selenium Project Using Maven

Image
  We will use Eclipse IDE and Maven for building the Selenium WebDriver test framework. Launch the Eclipse IDE. Create a new project by selecting [File -> New -> Other] from Eclipse Main Menu. On the New dialog, select [Maven -> Maven Project] as shown in the following screenshot: Click on [Next] , the New Maven Project dialog will be displayed. Select the [Create a simple project (skip archetype selection)] check-box and set everything to default and click on the Next button as shown in the following screenshot:   On the New Maven Project dialog box, enter base package name (like com.myproject.app ) in Group Id and project name (like myproject ) in Artifact Id textboxes. You can also add a name and description but it is optional. Set everything to default and click on the [Finish] button as shown in the following screenshot: Eclipse will create the myproject project with