Sunday 28 September 2014

Taking Screen Shots in WebDriver

Taking ScreenShots in WebDriver becomes quite easy by using one of its class known as "TakesScreenshot".

A small code snippet in your framework adds this functionality of taking screenshots using WebDriver:


public takesSnapshot (String suffix){
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Storing the screenshot in the testsuite-output folder
try {
FileUtils.copyFile(scrFile, new File("..\\testsuite-output\\VedioScreenshot_"+suffix+".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return this;
}


Add the above method of taking ScreenShot in @AfterSuite and now your tests are well accustomed to take screenshots after each test case finishes.


No comments:

Post a Comment