问题
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