使用testng框架在selenium webdriver中生成脚本后,如何生成测试报告,错误处理,截屏并保存到桌面上的文件夹。
答案 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.
}