使用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());

结果

相关推荐
AlunYegeer9 分钟前
MyBatis 传参核心:#{ } 与 ${ } 区别详解(避坑+面试重点)
java·mybatis
乱蜂朝王18 分钟前
使用 C# 和 ONNX Runtime 部署 PaDiM 异常检测模型
开发语言·c#
少许极端21 分钟前
算法奇妙屋(四十)-贪心算法学习之路7
java·学习·算法·贪心算法
波诺波22 分钟前
p1项目system_model.py代码
开发语言·python
危笑ioi23 分钟前
helm部署skywalking链路追踪 java
java·开发语言·skywalking
夕除30 分钟前
Mysql--15
java·数据库·mysql
静心观复31 分钟前
Python 虚拟环境与 pipx 详解
开发语言·python
卷心菜狗34 分钟前
Re.从零开始使用Python构建本地大模型网页智慧聊天机器人
开发语言·python·机器人
smileNicky35 分钟前
Linux 系列从多节点的catalina 日志中统计设备调用频次
java·linux·服务器
书到用时方恨少!1 小时前
Python NumPy 使用指南:科学计算的基石
开发语言·python·numpy