gpt4 book ai didi

java - 为屏幕截图创建动态文件名 Selenium Webdriver

转载 作者:行者123 更新时间:2023-12-01 11:47:31 25 4
gpt4 key购买 nike

在我的脚本中,我需要在多个位置截取屏幕截图。我想将所有屏幕截图保存在同一个文件夹中,每个文件都有唯一的名称。

有一些答案解释了如何将时间/日期戳附加到文件中,但我不需要。该脚本将每周运行一次并覆盖前一周的图像文件。

我正在使用 Java 和 Webdriver。这是我所拥有的:

String screenshots;
screenshots = "C:/eStore/Projects/Screenshots/Catalog/"; //location for images

File screenshots = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshots, new File("screenshots + 01Belts.jpg"));

最佳答案

因此,正如所讨论的,您可以找到解决此问题的方法:

@AfterMethod
public void tearDown(ITestResult result) throws IOException {
String location = "C:/eStore/Projects/Screenshots/Catalog/"; //location for images
String methodname = result.getName(); // fetching test method name
try {
File screenshots = ((TakesScreenshot) augmentedDriver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(
screenshots,
new File(location + methodName + "_" + ".png");
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.quit();
}
}

关于java - 为屏幕截图创建动态文件名 Selenium Webdriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29043315/

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