Java语言搭建Web自动化框架学习十一(Allure集成报表)

本文详细介绍了如何在项目中集成Allure插件,包括添加依赖、编码配置、maven-surefire-plugin配置,以及生成报表的方法。遇到的常见问题和解决方案也一并分享。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

核心代码

11.1在pom.xml导入allure依赖

		<dependency>
			<groupId>io.qameta.allure</groupId>
			<artifactId>allure-testng</artifactId>
			<version>2.13.0</version>
		</dependency>

11.2在pom.xml添加编码配置

防止中文乱码问题

	<properties>
		<!-- 文件拷贝时的编码 -->
		<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>

11.3在pom.xml添加maven-surefire-plugin

插件功能:可以通过maven运行testng的案例

	<properties>
         //在 已存在的properties中添加下列代码
		<aspectj.version>1.9.2</aspectj.version>
	</properties>
	<build>
		<plugins>
			<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}/aspectjweaver-${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>

11.4使用mvn命令生成报表

//cmd进入控制台,进入项目文件夹路径,在该路径下按顺序执行以下3个脚本
//需要每个脚本都执行完提示成功再接着执行下一个,第三个命令执行完后会自动打开浏览器,可以看到allure报表
mvn clean
mvn test
mvn io.qameta.allure:allure-maven:serve

11.5使用allure命令生成报表

前提:下载了allure插件,因为要用allure命令;还要配置好环境变量(配置allure的bin目录)。
因为11.4方式不用这2个前提更方便,就没亲自试这个方式。

//cmd控制台进入
allure serve allure-results

问题解决

11.1引入插件后,使用eclipse的maven test运行报错

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?参考文章解决:点击这里

11.2使用eclipse的maven test运行不报错后,使用mvn test命令运行又报上述错误(未解决)

按上述文章解析,检查自己maven的\apache-maven-3.6.1\conf\settings.xml里的jdk设置成和自己一致的jdk即可,
但过了两天,发现又出现这个问题,so。。。还是没搞定,哎呦。。有时间再研究看看吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值