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

大憨熊 提交于 2020-11-29 04:01:38

问题


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. Thanks for your help :)


回答1:


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:



来源:https://stackoverflow.com/questions/58728908/is-it-possible-to-have-screenshots-of-allure-report-between-steps-like-extent-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!