Tuesday, February 16, 2016

Capture ScreenShot


Selenium Webdriver provides TakeScreenShot interface to take the screen shot
go to url for more information :

http://selenium.googlecode.com/svn@7074/trunk/docs/api/java/index.html

This is very useful when ever there is failure we can take screen shot and store in location for future reference.

Script :
public class CaptureScreenShot {
public static void main(String[] args) throws InterruptedException, IOException {
// TODO Auto-generated method stub
Date date = new Date();
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
Thread.sleep(2000);
// maximize the window
driver.manage().window().maximize();
File scrfile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String mydate = date.toString();
FileUtils.copyFile(scrfile, new File("your path"+mydate+"test.png"));
}
}
view raw CaptureSS.java hosted with ❤ by GitHub