I'm looking for a solution to output a TestNG/Selenium screenshot in Jenkins. Ideally, when a Jenkins job runs I want to either have the images embedded into the Console Output or have a link display so the user can view the screenshot in a separate window.
Here's a function I'm using right now:
@AfterMethod
public void takeScreenShotOnFailure(ITestResult testResult) throws IOException {
if (testResult.getStatus() == ITestResult.FAILURE) {
System.out.println("Status: " + testResult.getStatus());
System.out.println("<img src=\"data:image/png;base64," +
((TakesScreenshot)driver).getScreenshotAs(OutputType.BASE64) + "\" ></img>");
}
}
The problem is that Jenkins displays the output as plain text. I tried copying the output into an html page and it looks fine. So it appears that the way Jenkins presents the information causes Firefox/Chrome to display the html code as plaintext. Any idea how to get around this? Or is there a better way to get TestNG's takescreenshot functionality to work with Jenkins?
You archive the screenshot using the "archive the artifacts" option in the "post build actions" of the jenkins project configuration page.To archive first u need to set the custom workspace for the project.The custom workspace should point to the root directory or the folder which is containing the folder of screenshots.Then after archiving all the screenshots will appear as links in the project page.Here "reports" will be folders containing the screenshots or any file.reports is under The "QTP" folder which is mentioned in the custom workspace.pls use slash instead of backslash in the archive the artifacts option.
Project page:
using custom workspace in jenkins
archiving the artifacts using post build actions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With