简体   繁体   中英

How to attach screenshot to azure report for selenium java cucumber

I am running my selenium java test suit in azure devops, after the execution i am able to see the result, but there is no attachment of failed screenshots. But when i run it in the local machine the cucumber report which is generating contains the screenshot.

Below is the code i have used to attach screenshot

@AfterStep
    public void embedScreenshot(Scenario scenario) throws Exception {
        if (scenario.isFailed()) {
            try {
                byte[] scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
                scenario.embed(scrFile, "image/png");
            } catch (WebDriverException somePlatformsDontSupportScreenshots) {
                System.err.println(somePlatformsDontSupportScreenshots.getMessage());
            }
        }
    }

Is there any plugin or anything else i can use to show the failed screenshot in the azure report?

I afraid there is not a plugin available to show the screenshot in azure report currently. For the screenshot is generated in the.html cucumber report. And azure devops doesnot support publishing generic HTML in build/release pipeline.

I guess the test result you saw is under the Tests tab of the azure pipeline build result page. And it is the xml format report which has been published to azure devops, not the html report which contains the screenshots.

There is feature request regarding this issue which has been submitted to microsoft develop team. You can go vote on it or create one of your own.

As a workaround, you can use the publish build artifacts task to publish the screenshots as artifacts of the pipeline.

steps:
- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: TestScreenshots'
  inputs:
    PathtoPublish: '$(System.defaultworkingdirectory)/target/home-page-html' #path to the test result folder(ie. html:target/home-page-html)
    ArtifactName: TestScreenshots

Then you can get the screenshots from the build Summary page, See below:

If the screenshots reside in multiple test result folders. You can use copy files task to copy the screenshots to a place and then publish to build artifacts.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM