Showing posts with label WebDriver. Show all posts
Showing posts with label WebDriver. Show all posts

Road to Setup Protractor and Selenium Webdriver

Protractor is web based end to end automation testing framework for Angular based application. It is most popular open source testing framework for Angular based application.
Protractor framework is node.js based program and written in java scripts. Protractor uses Webdriver to simulate and control web application.

Setup Protractor: Below installation is for windows machine.
1.    Download node js form link : Nodejs after downloading install exe in your machine.
2.    After clicking on ex you should get below screen:

Page Object Model for selenium webdriver

Like QTP, TestComplete and few other automation tools selenium webdriver does not provide any centralized repository where we can put object locator of page element. In POM object pattern we can accomplish this type approach.

What is POM:
In automated web testing, a Page Object is a class or object that represents a web page in your application. A Page Object hides the technical details about how you interact with a web page behind a more readable and business-focused facade. Following are the few points in details:
Page Object Model is a design pattern to create Object Repository for web UI elements. Like it provide you to option to put all locators in corresponding page (java file ) like for home page you  create a homepage java file and put all element locators of home page in same class.
Under this model, you should create java file like above ( ) home page and create functions related to this page  like clickHomeMenu, clickProduct() verfiyHomePage() etc.
So your page object class contains elements locator and corresponding function what you need to perform on that particular page.
Name of these function and object locator must be logically defined like elements name username , password, loginButoon and corresponding function should be like enterUserName(), enterPassword(), clickLoginButton()

Road to parallel execution of selenium webdriver test scripts using multithreading

In this post you will learn to how to execute selenium webdriver test script on two browser parallel using multithreading.
package com.test;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

public class GoogleSearchMultiThread extends Thread {

   private WebDriver driver;
   private String baseUrl;
   private String browsertype;

   public GoogleSearchMultiThread(String name, String browsertype) {
               this.browsertype = browsertype;

   public void run() {
        System.out.println("Thread- Started"
                                      + Thread.currentThread().getName());
        try {

          } catch (InterruptedException e) {
         } catch (Exception e) {
               // TODO Auto-generated catch block
        } finally {
       System.out.println("Thread- END " + Thread.currentThread().getName());

   // main method to create thread and run multiple thread
   public static void main(String[] args) {

               Thread t1 = new GoogleSearchMultiThread("Thread Firefox", "Firefox");
               Thread t2 = new GoogleSearchMultiThread("Thread IE", "IE");
               System.out.println("Starting MyThreads");
               System.out.println("Thread has been started");


   // set up method to initialize driver object
   public void setUp(String browsertype) throws Exception {

               if (browsertype.contains("IE")) {
                           File IEDriver = new File("IEDriverServer.exe");
                           driver = new InternetExplorerDriver();
               } else if (browsertype.contains("Firefox")) {
                           driver = new FirefoxDriver();
               baseUrl = "";
               driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

   // test scripts
   public void testGoogleSearch() throws Exception {
               driver.get(baseUrl + "/");
               driver.findElement(By.cssSelector("#ab_as > div")).click();
               driver.findElement(By.xpath("//input[@value='Advanced Search']"))

   // tear down function to close browser
   public void tearDown() {


In above class I use multithreading concept of java, when you run test it will execute two thread of test on at firefox browser and other on Internet explorer browser.

Road to parallel execution of selenium webdriver test using testng

In this post you will learn how to run selenium webdriver test scripts parallel in more two environments using testng suite, testng has a feature by which we can create multiple instance of a single testng class file.

In below example, I created a selenium webdriver test script for google search. Which will run on two browsers firefox and IE.

Integration of Webdriver ruby RSpec test suite with CircleCi

CircleCI has a continuous integration tool which builds and run your application in cloud environment. You can integrate and build your automation test scripts. CircleCI support following language:
1. Ruby.
2. PHP.
3. Java.
4. Python

Mobile Platform:
1. Android
2. iOS

How to setup:
1. You must have a git account.
2. Click on login circleci it will redirect git account login page.
3. Login in to git with your credential.
4. Click on Add Projects menu.
5. Choose a repository, of GitHub such as pushes and pull requests. It will kick off the first build immediately, and a new build will be initiated each time someone pushes commits.

Road to generate html report for Python Webdriver test suite using HTMLTestRunner

In my previous post ""Road to create test suite for python Webdriver scripts, I posted that how to create Suite file for webdriver python test script, but In this post I will show you how to integrate test suite with HTMLTestRunner to generate report in html format.

Before going through this post click here ( “Road to create test suite for python Webdriver scripts” ) to see both webdrive python unit test scripts.  I am taking these as example.

Follow below steps to setup:
1. Click on link "HTMLTestRunner" and download “”, and “” file put in your webdriver python project root folder.
2. Import all your test script in “” as below:
import WebdriverTest2
import WebdriverTest1

Road to create test suite for python Webdriver scripts

In this post I will show you how to create suite file for Webdriver python UnitTest.
Following are two webdriver python unit test script.

from selenium import webdriver
from import By
from selenium.webdriver.common.keys import Keys
import unittest, time, re

class WebdriverTest1(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.base_url = ""
    def test_Wikipedia(self):
        driver = self.driver
        driver.get(self.base_url + "/wiki/Main_Page")
    def tearDown(self):

if __name__ == "__main__":

Road to publish Webdriver TestNg report in Jenkins

In this post I will show you how to publish TestNg report on Jenkins server.

Installation TestNG plug-in.
1. After launching Jenkins server go to "Manage Jenkins>>Manage Plugins"
2. Enter TestNg in filter field, you will see “TestNg Results Plugin” like below screen.

3. Click on check box and then click on installation button.

Road to capture screen shot of failed Webdriver test script part2

In my previous post ( "Road to capture screen shot of failed webdriver test script part1") I have posted how to capture screen shot using exception handling, but in this post I will show you how to capture screen shot by overriding testng listeners.

Here is code ( where I override onTestFailure,  onTestSuccess and onTestSkipped methods of class TestListenerAdapter.  Created function CaptureScreenShot and called it into onTestFailure function.

package com.webdriver.test;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;

public class MyListner extends TestListenerAdapter{   
     public void onTestFailure(ITestResult result){ 
            System.out.println(result.getName()+" Test Failed \n");
     public void onTestSuccess(ITestResult result){
           System.out.println(result.getName()+" Test Passed \n");
     public void onTestSkipped(ITestResult result){
           System.out.println(result.getName()+" Test Skipped \n");
     public void CaptureScreenShot(ITestResult result){
           Object obj  = result.getInstance();
           WebDriver driver = ((FailedTestScreenCapture) obj).getDriver();
           File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
           try {
                  FileUtils.copyFile(scrFile, new File(“screenshot/” result.getName()+".png"));
           catch (IOException e) {

I called above created listeners java file in below “” TestNg file.

Road to setup Selendroid and create first test script of android application

About Selendroid:  Selendroid is an open source automation framework which drives of UI of android native, hybrid and mobile web application. It supports both emulator and real device. It uses Json Wire Protocol to run webdriver test scripts on device. It can be integrated with selenium grid for parallel execution on multiple nodes. No need any modification in application and not need source code to automate application.

  • JDK should be installed and java home path setup in your machine.
  • Android SDK should be installed on your machine and android path should be setup in your machine
  • Download Selendroid from link: Download
  • Selenium jar file from: Download
  • Eclipse.
  • Create new Emulator or attached real devices with you machine.

Difference between Selenium RC and Webdriver

S.N. Selenium RC Webdriver
1 It doesn’t supports Record and playback It doesn’t supports Record and playback
2 Core engine is Javascript based and interacts browser with remotely. Interacts natively with browser application
3 It is easy and small API As compared to RC, it is bit complex and large API.
4 Its API’s are less Object oriented Its API’s are entirely Object oriented
5 Need to start server before executing the test script No need to start server.
6 It does not support headless htmlunit browser. It  support headless htmlunit browser. Which is fater in execution
7 It doesn’t supports of moving mouse cursors. It supports of moving mouse cursors.
8 It does not supports listeners It supports the implementation of listeners
9 It does not support to test iphone/Android applications It support to test iphone/Android applications
10 Selenium RC is slower than Webdriver It is faster than selenium RC
11 Selenium RC has automatically generate Report in Html build report Webdriver has no command which automatically generate report

Road to capture screen shot of failed Webdriver script part1

In this post I will show you how to capture screen shot of failed test using exception handling and test marked failed in report.
In below example I handle exception using try catch block and call capture screen shot function in catch section, then throws exception make test fail.

Webdriver (Selenium ) Interview Questions and answers

Question 1: What is Selenium 2.0
Answer: Webdriver is open source automation tool for web application. WebDriver is designed to provide a simpler, more concise programming interface in addition to addressing some limitations in the Selenium-RC API.

Question 2: What is cost of webdriver, is this commercial or open source.
Answer: selenium  is open source and free of cost.

Difference between findElement and findElements of Webdriver

Here you will learn the difference between findElement() and findElements() function of Webdriver (Selenium).

1. findElement is use to locate single element and it return WebElement  object of first occurrences element on web page.
2. If element not found it will throw exception NoSuchElementException
3. Syntax: findElement(By by).

WebElement element = driver.findElement("Home"));;

1. findElements is use to find multiple element on webpage,  exp: as we need to count total number of row in table
2. It return List of WebElement object of all occurrences of element.
3. If element not found it will return empty List of WebElement object.
4. Syntax: List element = findElenets(By by)

List {WebElement} element = driver.findElement(By.xpath("//table/tr"));
int size = element.size();

Road to automate Html5 video with Webdriver (Selenium)

In this post I will show you how to automate HTML5 video.  To automate this we will use java scripts function to control video. So here we use “document.getElementById("Video ID")” , it return the HTML 5 video object. Using this object we can simulate video. Following are some java script function to handle video.
1. Play video
            document.getElementById("Video ID").play();  

Configuration of mobile user agent with webdriver

I this posts you will learn how to execute webdriver test script on browser using mobile user agent.

1. Install user agent in Firfox from link: User Agent
2. Install user agent in Google chrome from link: User Agent

Road to reading SVG graph values in Webdriver

Here is example of the reading svg graph values in java webdriver.
package com.test;

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class ReadSVGChartData {
    public WebDriver driver;
    public void setUp(){
         driver = new FirefoxDriver();
         driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    public void testDown(){
    public void testChart1() throws InterruptedException {
        //read chart value
        List elements = driver.findElements(By.xpath("//*[contains(@class,'yui3-svgRect yui3-seriesmarker')]"));
        WebElement toolTip = driver.findElement(By.xpath("//div[contains(@class,'yui3-chart-tooltip')]"));
        System.out.println("Specify Chart Type Data");
        for (WebElement el:  elements)
             String chartValue = toolTip.getText();
    public void testChart2(){  
        //open url
        //read chart value
        List elements = driver.findElements(By.xpath("//*[contains(@class,'yui3-svgCircle yui3-seriesmarker')]"));
        WebElement toolTip = driver.findElement(By.xpath("//div[contains(@class,'yui3-chart-tooltip')]"));
        System.out.println("\nDual Axes Chart Data");
        for (WebElement el:  elements)
             String chartValue = toolTip.getText();

BDD framework in Webdriver using C#

In my previous post, I have posted BDD framework in Webdriver using Java. In this post I will show you how to create BDD framework using C#. To achieve this I will use SpecFlow. This is same as Cucumber and you can write specs (features) file by using the same Gherkin language.
1. Install Visual studio.
2. Download and install SpecFlow from link :”click” For more detail about SpecFlow go to link ”click
3. Download NUnit Test Adapter from link:”click”.
Steps to create project: 
1. Go to File >>New >>Project and click.
2. Select Visual C# >> Class Library.
3. Enter project name into name filed and click on "OK" button, as below screen.

Java WebDriver BDD framework using Cucumber-JVM

In this post I will show you how to create BDD framework in webdriver selenium using cucumber-jvm. Cucumber –JVM is based on cucumber framework which allows to writes feature file in plain text using Gherkin language, This feature is supported by step definitions file which has implemented automation code of Webdriver.
This post cover maven based java webdriver BDD framework using cucumber for Google advance search scenario, Following are the steps to write scenario for BDD framework:
1.  First create a maven eclipse project.
                    ******** com/maven/test
                    ******** com/maven/test