jenkinsselenium-webdriverextentreportsselenium-extent-report

Screenshot is not attached to the extend report when ran in Jenkins only


When using remote-webdriver instance of BrowserStack, only when ran in Jenkins, the failed screenshot is not attached to the report. please help. folder structure is ExtentReport\Screenshots

screenshot is missing

I tried Extent Report: Not able to see the screenshots on other machine this but it's not resolve the issue.

public void onTestFailure(ITestResult result) {
        testMap.get().fail(result.getThrowable());
        //add screenshot for failed test.
        WebDriver driver= WebDriverFactory.getDriver();
        //experimental to get screenshot
        driver = new Augmenter().augment(driver);
        String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
        TakesScreenshot ts = (TakesScreenshot) driver;
        File source = ts.getScreenshotAs(OutputType.FILE);
        String destination = System.getProperty("user.dir") + "/ExtentReport/" + "/Screenshots/" + result.getMethod().getMethodName() + dateName + ".png";
        File finalDestination = new File(destination);
        try {
            FileUtils.copyFile(source, finalDestination);
        } catch (IOException e) {
            e.printStackTrace();
        }
        testMap.get().addScreenCaptureFromPath(destination,result.getMethod().getMethodName());

    }

Solution

  • Based on the answer of ravi creed,

    HTML : Unable to view the base64 image in html report

    String base64Screenshot ="data:image/png;base64," + ((TakesScreenshot) Objects.requireNonNull(driver)).getScreenshotAs(OutputType.BASE64);
            testMap.get().addScreenCaptureFromBase64String(base64Screenshot).getModel().getMedia().get(0);
    

    I managed to solve this using above code.Once click on base64 img, it opens the actual screenshot. enter image description here