selenium webdriver - 报告生成,截屏并保存到桌面上的文件夹

时间:2014-02-10 06:16:24

标签: error-handling selenium-webdriver report screenshot testng

使用testng框架在selenium webdriver中生成脚本后,如何生成测试报告,错误处理,截屏并保存到桌面上的文件夹。

1 个答案:

答案 0 :(得分:0)

截取屏幕并保存到桌面上的文件夹的代码。

public static void ScreenShot() throws IOException {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.yahoo.com/");
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Takes screenshot
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    // Now you can do whatever you need to do with it, for example copy somewhere
    String path;
    path = "C:/Users/owner/Desktop/screenshots/" + scrFile.getName();//goes to the path and automatically gives name
    FileUtils.copyFile(scrFile, new File(path)); //copies the screenshot file to the given path.

}