gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:10:29 24 4
gpt4 key购买 nike

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

最佳答案

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

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.

}

关于error-handling - selenium webdriver - 报告生成,截屏并保存到桌面上的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21670261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com