Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output TestNG screenshot to Jenkins

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?

like image 284
StockBreak Avatar asked Sep 29 '22 07:09

StockBreak


1 Answers

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:

enter image description here

using custom workspace in jenkins

enter image description here

archiving the artifacts using post build actions

enter image description here

like image 167
Sudharshan Ramaiah Avatar answered Oct 05 '22 08:10

Sudharshan Ramaiah