2016-03-04 54 views
0

使用傾斜報告框架,當某個步驟失敗時,我們可以通過使用@Attachment註釋調用方法來附加截圖或日誌。在掛鉤後使用黃瓜jvm在Allure報告中附加附件

​​

但這意味着我必須在斷言前的每一步中明確調用此方法(attachLog())。這似乎不合理。

在CucumberJvm中,「後」掛鉤是附加屏幕截圖或日誌的好方法。我們通過檢查場景狀態並根據結果附加屏幕截圖/日誌來實現此目的。

我試着在「hook」之後調用上述方法(attachLog())在cucumberJvm中。但不幸的是沒有工作。

有沒有解決方案,使這項工作?

乾杯 維諾德

回答

0

您可以覆蓋從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>