0

Currently I am able to see my *.png files in my local directory and when opening my extent report html, I can see the screenshots. When I do the same in Jenkins and use the publish html plugin for the extent html report while also moving the *.png files to a subdirectory where the html file is stored, I am not able to see the screenshots in the report. I can see in the jenkins build console output the *.png files are indeed being moved to the specified directory yet not showing in the html report.

Below is the code I have for my screenshot logic and the location for the screenshot files, as well as some of the jenkins scripts for the html plugin and moving the files to their respective directory:

Screenshot method:

public static String getScreenshot(String screenshotName) {
    TakesScreenshot ts = (TakesScreenshot) BrowserFactory.getBrowser();
    File srcfile = ts.getScreenshotAs(OutputType.FILE);
    //jenkins path
    String screenshotLocation = System.getProperty("user.dir") + File.separator + "test-output" + 
            File.separator + "extent" + File.separator + screenshotName + getCurrentDate() + ".png";
    File destLocPath = new File(screenshotLocation);
    try {
        FileUtils.copyFile(srcfile, destLocPath);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return screenshotLocation;
}

Jenkins:

sh "mvn clean test -Djdk.tls.client.protocols=TLSv1.2"
sh "mkdir -p TestResults"
sh "mv ./test-output/extent/AllTestCasesReport*.html TestResults/"
sh "mkdir -p TestResults/Screenshots"
sh "mv ./test-output/extent/*.png TestResults/Screenshots/ || error=true"

publishHTML([allowMissing: false,
            alwaysLinkToLastBuild: true,
            keepAll: true,
            reportDir: 'TestResults',
            reportFiles: 'AllTestCasesReport*.html',
            reportName: 'UI_Test_Report',
            escapeUnderscores: 'false'])

Console output in Jenkins:

07:34:34  [Pipeline] sh
07:34:34  + mkdir -p TestResults
07:34:34  [Pipeline] sh
07:34:34  + mv ./test-output/extent/AllTestCasesReport_2023_05_02-12_27_38.html ./test-output/extent/AllTestCasesReport_2023_05_03-07_33_35.html TestResults/
07:34:34  [Pipeline] sh
07:34:35  + mkdir -p TestResults/Screenshots
07:34:35  [Pipeline] sh
07:34:35  + mv ./test-output/extent/test2023_05_02-03_30_30.png ./test-output/extent/test2023_05_02-03_30_31.png ./test-output/extent/test2023_05_02-03_30_32.png ./test-output/extent/test2023_05_02-03_30_39.png ./test-output/extent/test2023_05_02-03_30_52.png ./test-output/extent/test2023_05_02-03_30_53.png ./test-output/extent/test2023_05_02-03_30_54.png ./test-output/extent/test2023_05_02-03_30_55.png ./test-output/extent/test2023_05_02-03_30_56.png ./test-output/extent/test2023_05_02-03_30_57.png ./test-output/extent/test2023_05_02-03_30_58.png ./test-output/extent/test2023_05_02-03_30_59.png ./test-output/extent/test2023_05_02-03_31_00.png ./test-output/extent/test2023_05_02-03_31_01.png ./test-output/extent/test2023_05_02-03_31_02.png ./test-output/extent/test2023_05_02-03_31_03.png ./test-output/extent/test2023_05_02-03_31_04.png ./test-output/extent/test2023_05_02-03_31_05.png ./test-output/extent/test2023_05_02-03_31_06.png ./test-output/extent/test2023_05_02-03_31_07.png ./test-output/extent/test2023_05_02-03_31_08.png ./test-output/extent/test2023_05_02-03_31_09.png ./test-output/extent/test2023_05_02-03_31_10.png ./test-output/extent/test2023_05_02-03_31_11.png ./test-output/extent/test2023_05_02-03_31_15.png ./test-output/extent/test2023_05_02-03_31_16.png ./test-output/extent/test2023_05_02-03_31_17.png ./test-output/extent/test2023_05_02-03_31_18.png ./test-output/extent/test2023_05_02-03_31_19.png ./test-output/extent/test2023_05_03-07_33_44.png ./test-output/extent/test2023_05_03-07_33_45.png ./test-output/extent/test2023_05_03-07_33_46.png ./test-output/extent/test2023_05_03-07_33_52.png ./test-output/extent/test2023_05_03-07_33_53.png ./test-output/extent/test2023_05_03-07_34_05.png ./test-output/extent/test2023_05_03-07_34_06.png ./test-output/extent/test2023_05_03-07_34_07.png ./test-output/extent/test2023_05_03-07_34_08.png ./test-output/extent/test2023_05_03-07_34_09.png ./test-output/extent/test2023_05_03-07_34_10.png ./test-output/extent/test2023_05_03-07_34_11.png ./test-output/extent/test2023_05_03-07_34_12.png ./test-output/extent/test2023_05_03-07_34_13.png ./test-output/extent/test2023_05_03-07_34_14.png ./test-output/extent/test2023_05_03-07_34_15.png ./test-output/extent/test2023_05_03-07_34_16.png ./test-output/extent/test2023_05_03-07_34_17.png ./test-output/extent/test2023_05_03-07_34_18.png ./test-output/extent/test2023_05_03-07_34_19.png ./test-output/extent/test2023_05_03-07_34_20.png ./test-output/extent/test2023_05_03-07_34_21.png ./test-output/extent/test2023_05_03-07_34_22.png ./test-output/extent/test2023_05_03-07_34_23.png ./test-output/extent/test2023_05_03-07_34_28.png ./test-output/extent/test2023_05_03-07_34_29.png ./test-output/extent/test2023_05_03-07_34_30.png ./test-output/extent/test2023_05_03-07_34_31.png ./test-output/extent/test2023_05_03-07_34_32.png TestResults/Screenshots/
07:34:35  [Pipeline] publishHTML
07:34:35  [htmlpublisher] Archiving HTML reports...
07:34:35  [htmlpublisher] Archiving at BUILD level /var/lib/jenkins/workspace/_UI_Automation_Tool_feature-loci/TestResults to /var/lib/jenkins/jobs/E-SCLF/jobs/UI_Automation_Tool/branches/feature-loci/builds/21/htmlreports/UI_Test_Report

Why is it that they are moving to TestResults/Screenshots/ yet I am unable to view them when opening the html file from the Jenkins URL UI Test Report?

wheelerlc64
  • 435
  • 2
  • 5
  • 17

0 Answers0