【问题标题】:Is it possible to have screenshots of allure report between steps like extent report?是否可以在范围报告等步骤之间有诱惑报告的屏幕截图?
【发布时间】:2019-11-06 11:16:44
【问题描述】:

我正在使用 allure 报告为我的测试生成报告。之前我使用extent报告。如您所知,在范围报告中,您可以按创建它们的顺序添加日志和屏幕截图,但在魅力报告中,所有屏幕截图都将在步骤结束时显示。

我的问题:是否可以在步骤之间显示屏幕截图?我想在每个步骤之后创建一个屏幕截图,我想在正确的位置看到它们,而不是在报告末尾 谢谢你的帮助:)

【问题讨论】:

    标签: java selenium selenium-webdriver allure selenium-extent-report


    【解决方案1】:

    您可以在步骤中通过截图来调用方法:

    @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)));
    }
    

    报告:

    【讨论】:

    • 感谢您的回复。但如果我在一种方法中有一些步骤,屏幕截图将出现在最后。对?我在问题中附加了另一张图片。
    • 所有带有screenshot()方法的@Step里面都会有截图。将screenshot() 方法添加到Check if the Log in was successful,您将获得所需的屏幕截图。
    • 但是不可能在方法中为Allure.step("something") 使用它。对吗?
    • 可以使用Allure.addAttachment(),查看答案更新
    • 我也测试了这个方法。更改附加文件名有助于更轻松地找到它。但它仍然出现在最后而不是它必须出现的地方。
    猜你喜欢
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 2018-11-28
    • 2021-12-27
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多