【问题标题】:Attaching attachments in Allure reports using cucumber jvm after hooks在钩子后使用黄瓜 jvm 在 Allure 报告中附加附件
【发布时间】:2016-03-04 10:30:43
【问题描述】:

使用 Allure 报告框架,当步骤失败时,我们可以通过调用带有 @Attachment 注释的方法来附加屏幕截图或日志。

@Attachment(value = "Message", type = "text/plain")
public String attachLog(){
    return "Hello, Test failed!";
}

但这意味着我必须在断言之前的每个步骤中显式调用此方法( attachLog() )。这似乎不合理。

在 CucumberJvm 中,“after”钩子是附加屏幕截图或日志的好方法。我们通过检查场景状态并根据结果附加屏幕截图/日志来做到这一点。

我尝试在 cucumberJvm “after” 钩子中调用上述方法( attachLog() )。但很遗憾没有奏效。

是否有解决方案来完成这项工作?

干杯 维诺德

【问题讨论】:

    标签: cucumber-jvm allure


    【解决方案1】:

    您可以从ru.yandex.qatools.allure.cucumberjvm.AllureRunListener 覆盖测试失败方法

    public class CustomAllureListener extends AllureRunListener {
    
    
        @Override
        public void testFailure(Failure failure) {
            super.testFailure(failure);
            if (!failure.getDescription().isSuite()) { // check is needed to avoid double attaching
                 attachFailed();
            }
        }
    
        @Attachment(value = "Message", type = "text/plain")
        public String attachFailed(){
            return "Test failed!";
        }
    }
    

    别忘了更改pom.xml文件中的监听器

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <testFailureIgnore>false</testFailureIgnore>
                    <argLine>
                        -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                    </argLine>
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>com.mycompany.testing.CustomAllureListener</value>
                        </property>
                    </properties>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
    

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 2022-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 2019-08-02
      相关资源
      最近更新 更多