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

结果

相关推荐
创梦流浪人13 小时前
Soli Admin:面向复杂业务场景的模块化企业后台基础平台
java·erp·后台管理系统
CoderCodingNo13 小时前
【CSP】CSP-J 2025真题 | 多边形 luogu-P14360 (相当于GESP六级水平)
开发语言·c++·算法
程序员侠客行13 小时前
Tomcat 网络I/O模型浅析
java·tomcat·web
一直都在57213 小时前
AQS详解
java·开发语言
zero159713 小时前
Python 8天极速入门笔记(大模型工程师专用):第二篇-Python基础入门(变量、数据类型、print输出)
开发语言·笔记·python
sheji341613 小时前
【开题答辩全过程】以 校园帮系统为例,包含答辩的问题和答案
java·spring boot
koping_wu13 小时前
【Java并发】CompletableFuture详解:常用API和底层原理
java·开发语言·python
填满你的记忆13 小时前
《Java 面试常见题型(2026最新版,背完直接能面)》
java·开发语言
小松加哲13 小时前
# Spring Aware 与 BeanPostProcessor:作用、使用与原理(源码级)
java·后端·spring
人还是要有梦想的13 小时前
QT的基本学习路线
开发语言·qt·学习