July 17, 2014

GEB -- Introduction

These days I am working on a new autoamtion tool called GEB(http://www.gebish.org/). GEB  is browser autoamtion tool which allows you to use Webdirver, jquery, POM and Groovy

Geb is built on top of the WebDriver browser automation library.

WebDriver utilizes native browser drivers to perform its automation. This is an important distinction for purposes of web testing—using Geb and WebDriver gives you the assurance that your application is behaving correctly in the browsers you test it on. It also provides access to browser commands that are simply inaccessible without native driver support.

Below are the advantages of GEB:

  1. Power of WebDriver
  2. Elegance of jQuery content selection
  3. Robustness of Page Object modeling
  4. Expressiveness of the Groovy language
Geb provides first class support and integration with common testing frameworks and build tools, including JUnit, Spock, Grails, Maven and Gradle.

If you want to write Elegant and powerful test cases then use 3GS
Spock  -- GEB Shines with Spock.

May 19, 2014

Download file using Selenium WebDriver by using Firefox Profile

This post will explain how to download files using selenium webdriver.

We need to create a firefox profile and set  preferences for that profile to save the file in desired location without showing the download or save to window

Below is the code:

March 3, 2014

Uploading a file using AutoIt

As we all know, Selenium will not support window based elements. To upload/download we need to use some third party tools.

Below post explains how to upload a file from local drive using AutoIt.

(This code is to select a file from window after clicking on browse button from web page, After this we have click on upload button from web page)

WinWaitActive("File Upload")

Write this code in Notepad and save the file as “Upload.au3”
Right Clicked on the created file “Upload.au3” and click on Compile Script.
You will get “Upload.exe” file

Call this file in Selenium script or in RFT script as below:

Process proc = Runtime.getRuntime().exec("C:\\Temp\\ Upload.exe");

Sample Selenium Code using AutoIt upload:

public class Upload {
public WebDriver driver;

public void setUp() throws Exception {
driver= new FirefoxDriver();
public void testTestScenario1() throws Exception
Process proc = Runtime.getRuntime().exec("C:\\Temp\\Upload.exe");
driver.findElement(By.xpath("//input[@title='Upload file']")).click();

public void tearDown() throws Exception {

March 2, 2014

Cross BrowserTesting using Selenium Webdriver and TestNG

This is an attempt to explain the feature of selenium webdriver and TestNG.

Generally we will run a single test case or script at a time. If you want to run  a single test on different browsers it is possible with selenium webdriver and TestNG. Test will be executed parallel in two browsers.

Lets see..how we can achieve this


Sample Script:
Create a sample webdriver script using TestNG and in that script define a parameter using @Parameter annotation.

Below is the sample script:

Create TestNG:
Create a testNG.xml file to run your script. Parameter value we can pass it from here.

Below is the sample TestNG.xml file

Run your TestNG.xml file and three browsers will open and script will run on 3 browsers parallel.

February 25, 2014

Screenshot on Failure using Selenium WebDriver

Below post explains you how to capture screenshot when scripts fails using Selenium WebDriver.

In this script I used simple try --Catch and Finally blocks..if any error occurs in try block control will go to catch block.

In Catch block i have written code for capturing screenshot and flag is set to true.

If the flag is true then finally block statement will be executed.

In Finally block  I have written exception that will raise an exception so that you can see the results if the script as failure. 

Below is the code.....

January 4, 2014

New Features in Selenium IDE (2.5.0)

I Just noticed on 2nd Jan that a new version of selenium is released. I Just had a glance at release notes there are 3 enhancements and few fixes to existing issues.

But today when I open selenium IDE I saw the enhancements..they are really useful...

Below is Release Notes for 2.5.0

I would like to talk about a new Enhancement:

1. Select an element for a command by clicking on the element in the browser window

This is a new feature added to selenium IDE.

They added new Button Select in the Target field.

How it works:

Select a row in selenium IDE test case Pane
Click on select and move your cursor to the element which you want to locate.

In below example i would like to find locator for "Search Selenium:"

It will automatically identify the xpath or CSS or any other appropriate way to find locator...

Try this feature this is really awesome feature from Selenium.

2. Start playing a test suite from any test case (Using right click menu)

If you already have a test suite in place (Ex: A test suite with  5 test cases) and you want to run from 2nd test case.  The newly added feature supports those kind of requirement.

Just you need to right click on the specific test case in test suite and select Paly Test suite from here. Execution of Test Suite starts from that particular test case.

See below screenshot for more details

3. Add a new test case using a keyboard shortcut (ctrl-N or cmd+N) 

From selenium IDE you can a new test case by using keyboard shrotcut CTRL+N..It will automatically add new test case in selenium IDE.

Hope all these feature are very helpful for selenium IDE users...


January 1, 2014

Get row count based on row text

Below post explains how to get the count of the row.

Generally we will have scenarios like get a particular text from the table, but in this example i am trying to get the number of the row based on the row text.

In this example a table contains number of rows and each row represents a company name. If we have row number we can get the company name easily...the below scenarios is different  ..based on the company name it will find out the number of the row.

December 13, 2013

Handling Cascading Dropdowns (Example for AJAX)

Below post explains you how to handle Cascading Dropdowns. It a good example for Ajax.

Each time the selection of one the DropDownList controls changes, the CascadingDropDown makes a call to a specified web service to retrieve the list of values for the next DropDownList in the set.

CascadingDropDown enables a common scenario in which the contents of one list depends on the selection of another list and does so without having to embed the entire data set in the page or transfer it to the client at all.

Below code explains how to handle Cascading drop downs:

August 28, 2013

Handling HTTPS sites Or Handling Security Certificate Errors using Selenium WebDriver

Selenium webdriver is used to automate web applications. Web applications generally starts with http://www.example.com......But some websites like internal websites or banking or secured web sites will starts with https://www.example.com. 

Below is one of the approach to handle https site while you are running from InternetExplorer.

Here we need to click the second option to go in to website.

Here we are taking help of Java script to click the second link 

Below is the code for handling https site..

package scripts;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class HttpsTest {
WebDriver driver;
public void httpsTest() throws Exception {
                //Java script to click the link
              //assert the title of the page
Assert.assertEquals(driver.getTitle(), "Welcome to Tech Mahindra Universe");
System.out.println("asssert successfull");
public void beforeTest() {
//launch Internet explorer
System.setProperty("webdriver.ie.driver", "F:\\Jar\\IEDriverServer.exe");
driver=new InternetExplorerDriver();

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

public void afterTest() {

Hope this post will be useful......

August 4, 2013

Get Values from Dropdown (Birthday field in Gmail registration )

Below is the sample script to get  values or options from a dropdown.

Below is the image of Birth Month dropdown

The Birth Month field is not a Drop down. If you want to get all the values from dropdown first we need to click on the arrow mark and then we can get all the values of dropdown.

Here in the below example..first click on the drop down arrow then all the elements (Month options) will be visible and then you can get all the values of dropdown.
package one;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Gmail_Reg {
public WebDriver driver;

public void setUp() throws Exception {
//Specify the browser
driver=new FirefoxDriver();
//declare globally wait
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//maximize the window

public void tearDown() throws Exception {
//close the browser

public void testGmail_Reg() throws Exception {

//click on the arrow mark
//get all the vlaues of dropdown
List x=driver.findElements(By.xpath("//div[@class='goog-menu goog-menu-vertical']/div"));
System.out.println("Size of the dropdown : "+x.size());
//print dropdown options
for (int i = 0; i < x.size(); i++) {



Size of the dropdown : 12