使用Allure作为测试报告生成器(Java+Selenium)

背景

JAVA项目中原先用Jenkins+selenium+selenium grid来日常测试UI并记录。

问题

当某一个testSuite失败时,当需要确认UI regression issue还是selenium test case自身的问题,需要去jenkins中查log,一般得到的是"Can not find element xxxxxx by path xxx",但又无法确定具体是什么问题,又得去grid server录频中找具体问题,定位耗时。

解决方案

在log文本和grid server录屏中间增加一个图片层级,引入Allure来记录报错截屏。

实施

pom.xml 文件

依赖:

bash 复制代码
<!-- allure -->
<dependency>
  <groupId>io.qameta.allure</groupId>
  <artifactId>allure-testng</artifactId>
  <version>2.12.1</version>
  <scope>test</scope>
</dependency>

<!-- allure相关依赖 -->
<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.8.10</version>
</dependency>

<!-- testNG依赖 -->
<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.14.3</version>
  <scope>test</scope>
</dependency>

插件:

bash 复制代码
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
						<allure.results.directory>${project.basedir}/target/allure-results</allure.results.directory>
                    </systemPropertyVariables>
                    <parallel>methods</parallel>
                    <threadCount>10</threadCount>
                </configuration>
            </plugin>
        </plugins>

在package: test.selenium.framework 中的Browser 类

// allure-report

try {

Allure.addAttachment(name, "image/png", Files.newInputStream(file.toPath()),".png");

} catch (IOException e) {

e.printStackTrace();

}

Allure.addAttachment("Error message", "text/csv", throwable.toString());

结果

相关推荐
Edward111111111 天前
3月17枚举
java·开发语言
Emberone1 天前
从C到C++:一脚踹开面向对象的大门
开发语言·c++
凡。。。2961 天前
阿里云产品说明
java
JosieBook1 天前
【C#】C# 所有关键字总结
开发语言·算法·c#
蓝天守卫者联盟11 天前
2026乙酸乙酯回收设备厂家选型与技术实践
java·jvm·python·算法
于先生吖1 天前
教育数字化转型 JAVA 国际版答题练习系统完整开发教程
java·开发语言
lakernote1 天前
EasyPostman 重大更新:正式支持插件模式,当前已上线 5 个官方插件
java·测试工具·开源·postman
Datacarts1 天前
亚马逊爆款选品:数据采集与三方服务商对接
开发语言·人工智能·python·信息可视化
赫瑞1 天前
Java中的 Dijkstra 算法
java·算法