【发布时间】:2018-09-11 08:41:08
【问题描述】:
我已经能够在 Firefox 无头模式下运行 selenium 测试用例,但是在截图时,截图不是网页的截图(在测试用例中测试的网页),而是截图背景(如显示的当前窗口(例如运行测试用例的 eclipse IDE))
截图功能
File screenShotFolder = new File("Screenshots");
WebDriver driver = getDriver();
try {
if (!screenShotFolder.exists() && !screenShotFolder.mkdir()) {
getLog().error(
"Cannot create a new file in the intended location. "
+ "" + screenShotFolder.getAbsolutePath());
}
File scrFile =
((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String filePath =
screenShotFolder.getAbsolutePath() + File.separator
+ imageName + ".png";
FileUtils.copyFile(scrFile, new File(filePath));
} catch (Exception e) {
e.printStackTrace();
}
还有其他需要设置的“选项”或“参数”吗?
【问题讨论】:
-
我发布的功能正常工作,问题是另一个功能正在获取背景截图并将其添加到最终报告中。
标签: java selenium firefox selenium-webdriver