美文网首页
web_auto测试报告Allure集成

web_auto测试报告Allure集成

作者: testerPM | 来源:发表于2020-02-09 16:17 被阅读0次

-------------------------Allure报表引入-------------------------------
Allure官网:https://docs.qameta.io/allure/

(1)pom集成依赖


<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-testng</artifactId>
    <version>2.12.1</version>
</dependency>


(2)pom编码设置,避免乱码
下面代码加在和<dependencies></dependencies>同级

<properties>
        <aspectj.version>1.8.10</aspectj.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    </properties>


(3)引入插件
(1)引入Maven编译插件maven-compiler-plugin(指定jdk版本,防止jdk版本发生变动)
(2)引⼊Maven Surefire插件(可以执行testng.xml文件--调用maven test命令)

下面代码加在和<dependencies></dependencies>同级

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <!-- maven-surefire-plugin 配合testng/junit执行测试用例的maven插件 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <!-- 测试失败后,是否忽略并继续测试 -->
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                        <!-- testng配置文件名称 -->
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <!--设置参数命令行 -->
                    <argLine>
                        <!-- UTF-8编码 -->
                        -Dfile.encoding=UTF-8
                        <!-- 配置拦截器 -->
                        -
                        javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjw
                        eaver-${aspectj.version}.jar"
                    </argLine>
                    <systemProperties>
                        <property>
                            <!-- 配置 allure 结果存储路径 -->
                            <name>allure.results.directory</name>
                            <value>${project.build.directory}/allure-results</value>
                        </property>
                    </systemProperties>
                </configuration>
                <dependencies>
                    <!-- aspectjweaver maven坐标 -->
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>






(4)生成testng.xml文件
第一步:
项目根目录下右键,new->other->搜索testng,如下图


image.png

第二步:


image.png

然后删除不要的包和类文件,将testng.xml拷贝到项目根目录下

image.png

项目出现x,但是代码却没有报错,解决办法:
项目右键->maven->update project即可解决

(5)生成Allure报表

1:Maven test构建项目
项目->run as-Maven test
项目构建成功,会在项目的target目录下生成allure-results目录,里面存的就是生成测试报告的一些数据,但是如果需要生成测试报告,还需要执行第二步(下面的2和3都可以生成测试报告)

2: cmd 执行命令 mvn io.qameta.allure:allure-maven:serve ---生成测试报告方式一

如何快速打开cmd,何如快速进入到项目的根目录下:
1 .找到项目存在哪个盘,进入到项目的根目录,输入cmd回车


image.png
image.png

2 :cmd命令行执行:mvn io.qameta.allure:allure-maven:serve
此命令执行前题(1 已经配置JAVA_HOME 2 已经配置Maven环境
MAVEN_HOME:D:\apache-maven-3.6.0
PATH:D:\apache-maven-3.6.0\bin)


image.png
image.png

3 项目的target目录下 输入 命令: allure server allure-result (生成测试报告方式二)
项目构建后(maven test),也可以通过在target目录下执行: allure server allure-result
但是前提是,本机要安装allure工具包

总结:
(1 ) 项目构建过程中(maven test)如果报如下错误:


image.png

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
翻译过来就是:此环境中未提供编译器,你可能使用jre运行而不是jdk
Eclipse默认在jre上运行,maven 编译需要系统环境变量中的jdk中的编译器,而自带的jre中并没有

解决办法:
将eclipse自带的jre换成系统环境变量的jdk
参考连接:https://blog.csdn.net/jiangguangchao/article/details/100105121
注意:
(1)控制台如果出现乱码现象:eclipse.ini最后一行加上 -Dfile.encoding=utf-8(全局变量)
(2)如果还是乱码,查看java 源文件如果是gbk的格式,导入eclispe,也必须设置的是gbk,否则会出现乱码(以后编写java源文件编码格式最好设置成utf8)---解决办法,将类文件代码copy,然后将java source File设置成utf8格式,将类文件代码再copy回去即可
window->preferences->general->content types->text->java source file

image.png

(2 ){project.build.directory} 是maven工程内置 直接引用即可{project.build.directory}= ./target

(3) 项目重新执行maven test,需要先执行maven clean(清空target目录下的所有内容)

相关文章

网友评论

      本文标题:web_auto测试报告Allure集成

      本文链接:https://www.haomeiwen.com/subject/etjbxhtx.html