我正在使用allure报告来为我的测试生成报告。之前我曾经使用extent报告。如您所知,在扩展区报告中,您可以按创建日志的顺序添加日志和屏幕截图,但在诱人的报告中,所有屏幕截图都将在步骤结束时显示。
我的问题:是否可以在步骤之间显示屏幕截图?我想在每个步骤之后创建一个屏幕截图,并希望在正确的位置看到它们,并在报告末尾看到not。感谢您的帮助:)
您可以在步骤中通过截屏调用方法:
@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);
}
更新:
import java.io.ByteArrayInputStream;
//...
@Step("Step 1")
public void step1(){
//...
Allure.addAttachment("Any text", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)));
}