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.

How to read write data in properties file using php

For reading and writing data into properties file I am using parse_ini_file() function in this post.
Create a file name with extension .properties like I have created below:


Reading Data: below code read data from above file using key:
function getValue($key)
{
    $ini_array = parse_ini_file("File.properties");
    $value =  $ini_array[$key];
    return $value;
}
getValue(“Name”);
getValue(“URL”);

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 (MyListner.java) 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 java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
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{   
           
     @Override
     public void onTestFailure(ITestResult result){ 
            CaptureScreenShot(result);
            System.out.println(result.getName()+" Test Failed \n");
     }
           
     @Override
     public void onTestSuccess(ITestResult result){
           System.out.println(result.getName()+" Test Passed \n");
     }
           
     @Override
     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) {
                e.printStackTrace();
           }
      } 
}

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

Road to create Virtual device (Emulator ) for beginner

In this post I will show you how to install android SDK , setup Android SDK path in system environments variable, How to update android API and how to create Virtual Devices.

Installation:
  1. Download Androd sdk exe or Zip file from link: download
  2. Install exe file in your machine or extract the zip file.
Setup Path:
1. Right click on the "My Computer" icon.
2. Click Properties
3. Click Advanced tab
4. Click Environment Variables button, You should see below screen:

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.

Prerequisites:
  • 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).

findElement:  
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).

Example:
WebElement element = driver.findElement(By.id("Home"));
element.click();

findElements: 
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)

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