Refer to Http://www.cnblogs.com/tobecrazy/p/3599568.html
Webdriver, you need to introduce:
ImportJava.io.File;ImportJava.io.IOException;ImportOrg.apache.commons.io.FileUtils;ImportOrg.openqa.selenium.OutputType;Import Org.openqa.selenium.TakesScreenshot;
Method
public static void Snapshot (Takesscreenshot drivername, String filename)
{
This method would take the screen shot, require-parameters, one is driver name, and another is file name
String Currentpath = System.getproperty ("User.dir"); Get Current Work folder
System.out.println (Currentpath);
File scrfile = Drivername.getscreenshotas (outputtype.file);
Now you can do whatever need to do with it, for example copy somewhere
try {
System.out.println ("Save snapshot Path is:" +currentpath+ "/" +filename);
Fileutils.copyfile (Scrfile, New File (currentpath+ "\ \" +filename));
} catch (IOException e) {
TODO auto-generated Catch block
System.out.println ("Can ' t Save screenshot");
E.printstacktrace ();
}
Finally
{
System.out.println ("screen shot finished");
}
}
Search for selenium on Baidu and then
Selenium Webdriver Implementation function