Why blank screenshot are getting attached in the extent reports when using Junit?

Viewed 53

I'm using Junit, cucumber framework for executing my test scripts. The setup and execution of code takes place on VDI.

Here is the below code, I'm using for attaching the screenshot in the Apphooks-

@AfterStep
    public void addScreenshot(Scenario scenario){

          final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
          scenario.attach(screenshot, "image/png", "image"); 
        
    }

Below is my extent.properties file content-

#extent.properties
extent.reporter.spark.start=true
extent.reporter.spark.out=target/MyReports/Spark.html

#Screenshot
screenshot.dir=target/MyReports/Screenshots/
screenshot.rel.path=../Screenshots/

#Adding folder name and non repeating pattern
basefolder.name=target/MyReports
basefolder.datetimepattern=d-MMM-YY HH-mm-ss

Screenshots are getting generated in the screenshot folder with the default names like embedded1, embedded2 etc. But the screenshots in the extent report is showing as a small blank box below my test step. Why so? enter image description here I don't think Output.BYTES needs a path to be explicitly given to attach the screenshots in the report.

1 Answers

AFAIK you have to pass a full absolute path of the picture to extent repots, not a relative path.
I guess the target folder is located inside the Selenium automation project.
In case of dynamic target folder like target/Reports_080920222112534/Screenshots
Let's say the Selenium project folder path is C:\seleniumProject and the above folder is in it, the full folder path will be C:/seleniumProject/target/Reports_080920222112534/Screenshots
I think the path should contain the screenshot image file itself too i.e. the full path passed to extent report should be something like C:/seleniumProject/target/Reports_080920222112534/Screenshots/screenshot.png

Related