In my index.html file the embedded screenshots are not displayed when using Jenkins with HTML Publisher plugin. The screenshots are shown only when running my tests locally.
In the index.html file shown in the HTML Publisher plugin when I click on one of the embedded empty screenshots I'm getting:
HTTP ERROR 404 Problem accessing /var/lib/jenkins/workspace/my_test/target/surefire-reports/Wed_Jan_23_14_33_19_UTC_2019.png. Reason:
Not Found
I have verified the screenshots get generated every time in this exact path. This is my code to set the screenshot location:
public void takeScreenshotMyOwn() {
File scrFile = ((TakesScreenshot)getDriver()).getScreenshotAs(OutputType.FILE);
try {
String reportDirectory = new File(System.getProperty("user.dir")).getAbsolutePath() + "/target/surefire-reports/";
File destFile = new File( reportDirectory + screenshotFileName());
FileUtils.copyFile(scrFile, destFile);
Reporter.log( htmlNewLine + htmlNewLine + "<a href='" + reportDirectory + destFile.getName() + "'> <img src='" + reportDirectory + destFile.getName() + "' height='200' width='340'/> </a>"+htmlNewLine);
} catch (IOException e) {
e.printStackTrace();
Reporter.log("Failed to create screenshot");
Reporter.log(e.getMessage());
}
}
What am I doing wrong? I have searched all over and haven't found a solution that works.