Closed PratibhaRamteke closed 4 years ago
Hi @anshooarora I am also facing same issue. Please help us out. We are dependent on you no such proper guide available anywhere on internet.
You should be able to see screenshots in Jenkins if you have used relative path. Remember, the image path needs to be relative to the report HTML file. So if your report and images are stored like so:
/reports
/report.html
/screenshots
0.png
1.png
Relative path would be:
../screenshots/0.png
../screenshots/1.png
@anshooarora Thanks buddy for your quick response. My problem is sort out. I am also attaching my code below. So, that it will help other as well. 👍
public void onTestFailure(ITestResult result) {
String excepionMessage=Arrays.toString(result.getThrowable().getStackTrace());
testReport.get().fail("<details>" + "<summary>" + "<b>" + "<font color=" + "red>" + "Exception Occured:Click to see"
+ "</font>" + "</b >" + "</summary>" +excepionMessage.replaceAll(",", "<br>")+"</details>"+" \n");
try {
Utilities.captureScreenshot();
testReport.get().fail("<b>" + "<font color=" + "red>" + "Screenshot of failure" + "</font>" + "</b>",
MediaEntityBuilder.createScreenCaptureFromPath(Utilities.screenshotName)
.build());
}
catch (IOException e) {
}
String failureLogg="TEST CASE FAILED";
Markup m = MarkupHelper.createLabel(failureLogg, ExtentColor.RED);
testReport.get().log(Status.FAIL, m);
rep.flush();
}
Screenshot Capture Utility: Everytime you will capture screenshot with unique name
public class Utilities extends Page {
public static String screenshotPath;
public static String screenshotName;
public static void captureScreenshot() throws IOException {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Date d = new Date();
screenshotName = d.toString().replace(":", "_").replace(" ", "_") + ".png";
FileUtils.copyFile(scrFile,
new File(System.getProperty("user.dir") + "/target/surefire-reports/html/" + screenshotName));
screenshotPath= System.getProperty("user.dir") + "\\target\\surefire-reports\\html\\" + screenshotName;
}
@anshooarora I have one more query. Can you please share any sample code of how to implement below method: testReport.get().addScreenCaptureFromBase64String(s)
I am unable to implement addScreenCaptureFromBase64String(s)
You should be able to see screenshots in Jenkins if you have used relative path. Remember, the image path needs to be relative to the report HTML file. So if your report and images are stored like so:
/reports /report.html /screenshots 0.png 1.png
Relative path would be:
../screenshots/0.png ../screenshots/1.png
@anshooarora I have used the same relative path , On My Local execution screenshot is visible but on Jenkins execution , screenshot is not visible on HTML report.
This is the same issue I am facing anshooarora/extentreports-java#990. but this issue has been closed. so opening the new one.
- I am not able to see screenshots in logger report upon integration with Jenkins
- Screenshots are visible in reports on my local machine
- Have tried giving both absolute and relative path for screenshots
- the issue is while attaching screenshots to any report. It is getting attached with the absolute path. like file://c:/
- On my local machine screenshots are accessible on opening them from report
- But when I publish the report using HTML publisher plugin, the report still tries to get the file from local path.
- I tried copying images to jobs folder created by jenkins. But as the path is absolute, the images are unavialable.
- how to attach images with relative path? so that they can be accessed in Jenkins as well. Any jelp would be helpful. Its bit urgent.
- Thanks
@PratibhaRamteke were you able to get the solution for this issue?
This is the same issue I am facing https://github.com/anshooarora/extentreports-java/issues/990. but this issue has been closed. so opening the new one.
I am not able to see screenshots in logger report upon integration with Jenkins
Screenshots are visible in reports on my local machine
Have tried giving both absolute and relative path for screenshots
the issue is while attaching screenshots to any report. It is getting attached with the absolute path. like file://c:/
On my local machine screenshots are accessible on opening them from report
But when I publish the report using HTML publisher plugin, the report still tries to get the file from local path.
I tried copying images to jobs folder created by jenkins. But as the path is absolute, the images are unavialable.
how to attach images with relative path? so that they can be accessed in Jenkins as well. Any jelp would be helpful. Its bit urgent.
Thanks