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 :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
} | |
} |