public class screen {
@Test
public void test() throws Exception{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
}
}
--------------------------------------------------------
Or try this program.
@AfterMethod
public void OnFailureTest(ITestResult result) throws IOException {
if (!result.isSuccess()) {
File imageFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
//String failureImageFileName = "C:\\Users\\prasanthi\\workspace\\Project\\XSLT_Reports\\screenShots\\" + result.getMethod().getMethodName() + new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime()) + ".png";
String failureImageFileName = "C:\\Users\\prasanthi\\workspace\\Project\\XSLT_Reports\\screenShots\\" + result.getMethod().getMethodName() + "().png";
File failureImageFile = new File(failureImageFileName );
if (failureImageFile.exists()) {
failureImageFile.delete();
}
FileUtils.moveFile(imageFile, failureImageFile);
}
/* driver.close();
driver.quit();*/
}
@Test
public void test() throws Exception{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
}
}
--------------------------------------------------------
Or try this program.
@AfterMethod
public void OnFailureTest(ITestResult result) throws IOException {
if (!result.isSuccess()) {
File imageFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
//String failureImageFileName = "C:\\Users\\prasanthi\\workspace\\Project\\XSLT_Reports\\screenShots\\" + result.getMethod().getMethodName() + new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime()) + ".png";
String failureImageFileName = "C:\\Users\\prasanthi\\workspace\\Project\\XSLT_Reports\\screenShots\\" + result.getMethod().getMethodName() + "().png";
File failureImageFile = new File(failureImageFileName );
if (failureImageFile.exists()) {
failureImageFile.delete();
}
FileUtils.moveFile(imageFile, failureImageFile);
}
/* driver.close();
driver.quit();*/
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.