0xM*_*M4x 5 java selenium selenium-webdriver allure selenium-extent-report
我正在使用allure报告来生成测试报告。早些时候我曾经使用范围报告。如您所知,在范围报告中,您可以添加日志和屏幕截图以创建它们,但在诱惑报告中,所有屏幕截图都将显示在步骤的末尾。
我的问题:是否可以在步骤之间显示屏幕截图?我想在每个步骤之后创建一个屏幕截图,并且我希望在正确的位置而不是在报告的末尾看到它们。
感谢您的帮助 :)
您可以在步骤中调用带有截图的方法:
@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);
}
Run Code Online (Sandbox Code Playgroud)
更新:
import java.io.ByteArrayInputStream;
//...
@Step("Step 1")
public void step1(){
//...
Allure.addAttachment("Any text", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23154 次 |
| 最近记录: |