Allure 生成测试报表

Allure官方文档参考地址:https://docs.qameta.io/allure/#_testng

1.在maven中添加依赖并进行相应的配置:

<!-- 实现版本控制 -->
<properties>
    <aspectj.version>1.8.10</aspectj.version>
</properties>

<!-- 导入allure-testng 的依赖 -->
<dependencies>
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.12.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<!-- 添加 build 元素,指定项目以什么样的方式去构建 -->
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
        <!-- 配置maven-surefire-plugin插件来使用maven命令来调用测试套件 -->
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <!--设置参数命令行-->
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
             <suiteXmlFiles>
               <!--代表的是要执行的测试套件路径/名称-->
               <suiteXmlFile>testng.xml</suiteXmlFile>
            </suiteXmlFiles>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

 

2.mvn 使用Maven命令执行,clean 清除target目录残留文件,test执行套件

 (1) 命令行执行

//前提:已经配置Maven环境
MAVEN_HOME:D:\apache-maven-3.6.0
PATH:D:\apache-maven-3.6.0\bin
//在项目根路径下打开cmd窗口,执行mvn clean test命令,项目开始构建
D:\Eclipse_workspace\web_auto>mvn clean test

(2) 在Eclipse中选中项目名右键选择:

点击Run后项目开始构建,直到项目构建完成后执行下一步;

补充:构建项目后如果出现以下情况:解决办法请参考博文地址:https://www.cnblogs.com/xiaozhaoboke/p/11202835.html

(3)在当前目录下打开cmd执行 allure serve target/allure-results

如果出现如下提示,则需要安装allure插件

D:\Eclipse_workspace\web_auto>allure serve allure-results
'allure' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

 (4)安装allure 插件,参考官方文档安装地址:https://docs.qameta.io/allure/#_installing_a_commandline

  Allure.zip 下载地址链接:http://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/

     allure-commandline-2.12.1.zip http://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.12.1/allure-commandline-2.12.1.zip

 

      下载=》解压=》进入bin目录=》执行allure.bat =》配置到path环境 D:\allure\allure-2.12.1\bin

//cmd验证
D:\Eclipse_workspace\web_auto>allure --version
2.12.1

(5) 再次执行第(3)步

D:\Eclipse_workspace\web_auto>allure serve allure-results
Generating report to temp directory...
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\2283257593
12518038\allure-report
Starting web server...
2019-07-17 17:40:14.105:INFO::main: Logging initialized @8623ms to org.eclipse.j
etty.util.log.StdErrLog
Server started at <http://192.168.1.3:58814/>. Press <Ctrl+C> to exitx

执行完成后默认浏览器自动打开report,或者复制URL重新刷新访问页面

 学习后总结分享,report报告中载入错误截图待续。。。