0xM4x
0xM4x

Reputation: 470

Is it possible to have screenshots of allure report between steps like extent report?

I'm using allure report to generate a report for my tests. earlier I used to use extent report. as you know, in extent report you can add logs and screenshot in order of creating them but in allure reports, all the screenshots are going to be shown at the end of steps.

My Question: Is it possible to show the screenshots between steps? I want to create a screenshot after each step and I want to see them in the right place and not at the end of the report.enter image description here enter image description here Thanks for your help :)

Upvotes: 5

Views: 26710

Answers (1)

Sers
Sers

Reputation: 12255

You can call method with taking screenshot in the step:

@Test(description = "Screenshot in Step")
public void screenshotInStepTest() {
    driver.get("https://www.google.com");
    step1();
    step2();
    step3();
}

@Step("Step 1")
public void step1(){
    System.out.println("step 1");
}
@Step("Step 2 with screenshot")
public void step2(){
    System.out.println("step 2");
    screenshot();
}
@Step("Step 3")
public void step3(){
    System.out.println("step 3");
}

@Attachment(value = "Screenshot", type = "image/png")
public byte[] screenshot() {
    return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}

Update:

import java.io.ByteArrayInputStream;
//...
@Step("Step 1")
public void step1(){
    //...

    Allure.addAttachment("Any text", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)));
}

Report: enter image description here

Upvotes: 6

Related Questions