我的詹金斯报告未显示跑步中捕获的屏幕截图。 (它们在MAC上运行)。但是,当我在本地(Windows计算机)上运行同一作业时,报告中会包含屏幕截图。
当我尝试打开图像时,它显示如下。它实际上无法找到图像的路径。
Error : http://*****-mac:8080/job/***Test/job/******/ws/target/screenshots/2019-01-14/Sign%20In20190114154253.png
Actual: http://*****-mac:8080/job/***Test/job/******/HTML_20Report/target/screenshots/2019-01-14/Sign%20In20190114154253.png
我正在使用以下代码捕获屏幕截图。它确实捕获了屏幕截图,我可以在实际位置看到它们。 我不知道什么时候做错了,这些图像在报告中不被视为链接/不可用:
public void captureScreenshot() throws IOException {
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String dateForScreenshots = dateFormat.format(date);
File localScreenshots = new File(new File("target/screenshots"), dateForScreenshots);
if (!localScreenshots.exists() || !localScreenshots.isDirectory()) {
localScreenshots.mkdirs();
}
System.setProperty("org.uncommons.reportng.escape-output", "false");// this is to create a link in ReportNG
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String destination = System.getProperty("user.dir") + "/target/screenshots/" + dateForScreenshots + "/" + getDriver().getTitle() + Utils.generateRandomString() + ".png";
File screenshotName = new File(destination);
//Now add screenshot to results by copying the file
FileUtils.copyFile(scrFile, screenshotName);
Reporter.log("<br> <img src='" + destination + "' height='90' width='160' /><br>");
Reporter.log("<a href=" + destination + "></a>");
}
答案 0 :(得分:0)
从此行
Error : http://*****-mac:8080/job/***Test/job/******/ws/target/screenshots/2019-01-14/Sign%20In20190114154253.png
我认为Jenkins在工作空间文件夹(ws
)中找不到目标分支。可能您需要在Jenkins作业中指定工作区文件夹(如在this中的回答),或者只是将destination
变量更改为类似(添加/HTML_20Report
):
String destination = System.getProperty("user.dir") + "/HTML_20Report/target/screenshots/" + dateForScreenshots + "/" + getDriver().getTitle() + Utils.generateRandomString() + ".png";