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

结果

相关推荐
无敌最俊朗@3 分钟前
Qt 多线程编程: moveToThread 模式讲解
java·开发语言
!停7 分钟前
深入理解指针(4)
开发语言·javascript·ecmascript
小白狮ww9 分钟前
Matlab 教程:基于 RFUAV 系统使用 Matlab 处理无人机信号
开发语言·人工智能·深度学习·机器学习·matlab·无人机·rfuav
penngo22 分钟前
Golang使用Fyne开发桌面应用
开发语言·后端·golang
程序员清风26 分钟前
别卷模型了!上下文工程才是大模型应用的王道!
java·后端·面试
go__Ahead28 分钟前
【Java】ThreadLocal源码解析
java
利剑 -~31 分钟前
Spring AI Alibaba 1.1版本
java·人工智能·spring
雨中飘荡的记忆33 分钟前
Guava工具库实战
java
while(1){yan}38 分钟前
JAVA中如何操作文件
java·开发语言·面试
SuperherRo39 分钟前
JAVA攻防-FastJson专题&各版本Gadget链&autoType开关&黑名单&依赖包&本地代码
java·fastjson·1.2.24·1.2.47·1.2.62·1.2.80