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

结果

相关推荐
间彧7 分钟前
SimpleDateFormat既然不推荐使用,为什么java 8+中不删除此类
java
间彧13 分钟前
DateTimeFormatter相比SimpleDateFormat在性能上有何差异?
java
间彧25 分钟前
为什么说SimpleDateFormat是经典的线程不安全类
java
MacroZheng32 分钟前
横空出世!MyBatis-Plus 同款 ES ORM 框架,用起来够优雅!
java·后端·elasticsearch
用户0332126663671 小时前
Java 查找并替换 Excel 中的数据:详细教程
java
间彧1 小时前
ThreadLocal实现原理与应用实践
java
若水不如远方1 小时前
Netty的四种零拷贝机制:深入原理与实战指南
java·netty
用户7493636848431 小时前
【开箱即用】一分钟使用java对接海外大模型gpt等对话模型,实现打字机效果
java
SimonKing2 小时前
一键开启!Spring Boot 的这些「魔法开关」@Enable*,你用对了吗?
java·后端·程序员
间彧2 小时前
Spring Boot集成Spring Security 6.x完整指南
java