Skip to main content

Add Screenshot in Cucumber Extent Report

There could be several ways to implement screenshot utility with Cucumber adapter. This is the one I think is a better Solution:

Extent report Byte screenshot

Step 1: Add method to capture screenshot

public byte[] getByteScreenshot() throws IOException 
    File src = ((TakesScreenshot) base.getDriver()).getScreenshotAs(OutputType.FILE);
    byte[] fileContent = FileUtils.readFileToByteArray(src);
    return fileContent;


  • TakeScreenshot is an interface that Indicates a driver that can capture a screenshot and store it in different ways. 
  • FileUtil is general file manipulation util. readFileToByteArray will read the content of image file in ByteArray. 

or You can directly convert to byte and return

public byte[] getByteScreenshot()
    return ((TakesScreenshot) base.getDriver()).getScreenshotAs(OutputType.BYTES);

Step 2: Add Screenshot configuration in


Step 3: In after hook call following line

public void af(Scenario scenario) throws IOException, InterruptedException
        scenario.attach(getByteScreenshot(), "image/png", scenario.getName());

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.