Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to capture the screenshot of failed testcase only among a set of testcases?

Answers were Sorted based on User's Feedback



How to capture the screenshot of failed testcase only among a set of testcases?..

Answer / suresh vemula

First we have to create a method of screen shot using java.

After that we have annotation in testng to identify the failure test case or methods using "iTestResult"

This iTestResult using only where annotation in aftermethod

@Aftermethod
Public void test(iTestResult.FAILURE==result.getStatus()){

Utility.screenshot(driver,result.getname());
}

Here utility.screenshot is java class to created for screenshot

Here getName() returns the failure test case name
Then you have to identify the failure test easily

Is This Answer Correct ?    3 Yes 0 No

How to capture the screenshot of failed testcase only among a set of testcases?..

Answer / kiran212

package TestNG;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Screenshot {
WebDriver driver;
@BeforeClass
public void setup() {
driver = new FirefoxDriver();
driver.get("http://google.com");
}

@Test
public void tc01() {
driver.findElement(By.xpath("wrong xpath"));
}
@Test
public void tc02(){

System.out.println(driver.getTitle());

}

@AfterClass
public void browserKill() {
driver.close();
}
//screenshot method for failure test cases
@AfterMethod(alwaysRun=true)
public void takeScreenShot(ITestResult result) throws IOException{
if(result.getStatus()==2){
String testName = result.getMethod().getMethodName();
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("D://"+testName+".jpeg"));
}
}
}

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More Selenium Interview Questions

What if you have written your own element locator and how would you test it?

0 Answers  


Tell me how you can find broken images in a page using selenium web driver?

0 Answers  


What does a concentrator do in the selenium network?

0 Answers  


What is the difference between captureentirepagescreenshot and capturescreenshot?

0 Answers  


How to do drag and drop in selenium?

0 Answers  


What are the different types of drivers available in webdriver?

0 Answers  


What happens if I run this command. Driver.get(“www.softwaretestingmaterial.com”) ;

0 Answers  


Explain how to assert text of webpage using selenium 2.0?

0 Answers  


What the webdriver supported mobile testing drivers do you know?

0 Answers  


How can we type text in a textbox element using selenium?

0 Answers  


List some of the operating systems that are supported by selenium webdriver.

0 Answers  


How to select a value from a drop-down?

1 Answers  


Categories