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

结果

相关推荐
zhangjw34几秒前
第4篇:Java数组与字符串:从基础用法到面试高频考点
java·java基础知识
俺爱吃萝卜8 分钟前
Spring Boot 3 + JDK 17:新一代微服务架构最佳实践
java·spring boot·架构
曹牧14 分钟前
Spring :component-scan
java·后端·spring
qq_120840937115 分钟前
Three.js 工程向:GLTFLoader 管线、Draco/KTX2 与资源管理
开发语言·javascript·ecmascript
下地种菜小叶23 分钟前
定时任务系统怎么设计?一次讲清任务注册、分布式调度、幂等执行与失败补偿
java·开发语言·数据库·oracle·rabbitmq
做个文艺程序员26 分钟前
Spring Boot 项目集成 OpenClAW【OpenClAW + Spring Boot 系列 第1篇】
java·人工智能·spring boot·开源
csbysj202039 分钟前
业务代表模式
开发语言
withelios39 分钟前
Java泛型全面理解指南
java
withelios39 分钟前
Java枚举全解析:从基础到高级使用技巧
java·后端
sghuter41 分钟前
AI重塑工程师:未来核心能力全景图
开发语言·perl·composer·symfony