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

  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: