寫這篇文章的目的
- 由于項目中有需要,所以在尋找一個方便展示的 report 框架
- 在網(wǎng)上看了好久劲件,決定使用 Allure掸哑,但是搜索了一下,發(fā)現(xiàn)好多的文章的介紹都不是特別的完善零远,照著試了一下苗分,但是,遇到了一些問題
- 因為牵辣,好多的配置都是按照 1.x 的版本來的摔癣,后來經(jīng)過自己的實驗,ok 了纬向,所以想著記錄一下择浊,方便日后再看。
Allure Report 簡介
Allure 是一個輕量級的逾条,靈活的琢岩,支持多語言,多平臺的report框架师脂。
可以方便的集成到各種框架中担孔,例如,TestNG危彩,Junit等攒磨。GitHub 地址
報告展示
OverView
OverView
Graphs
Graphs
如何集成
我的項目是 Maven + TestNG 的,以下都是以這個為例子
Pom 文件
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.0-BETA19</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
<version>3.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<properties>
<aspectj.version>1.8.9</aspectj.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.8</version>
</plugin>
</plugins>
</reporting>
修改 Listener(可以實現(xiàn)失敗的 case 自動截圖并在報告中展示)
public class AllureReporterListener extends BaseTest implements IHookable {
@Override
public void run(IHookCallBack callBack, ITestResult testResult) {
callBack.runTestMethod(testResult);
if (testResult.getThrowable() != null) {
try {
takeScreenShot(testResult.getMethod().getMethodName());
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Attachment(value = "Failure in method {0}", type = "image/png")
private byte[] takeScreenShot(String methodName) throws IOException {
File screenshot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
return Files.toByteArray(screenshot);
}
后續(xù)計劃
目前只是繼承了而已汤徽,看官方的介紹娩缰,allure 還提供了很多的 API 來實現(xiàn)更多的可以展示在報告中的東西,希望后續(xù)可以繼續(xù)谒府。拼坎。浮毯。