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

结果

相关推荐
小江的记录本几秒前
【Swagger】Swagger系统性知识体系全方位结构化总结
java·前端·后端·python·mysql·spring·docker
空太Jun2 分钟前
Spring Security 自定义数据库认证(初尝试)
java·数据库·spring
报错小能手2 分钟前
ios开发方向——swift内存基础
开发语言·ios·swift
minji...3 分钟前
Linux 多线程(四)线程等待,线程分离,线程管理,C++多线程,pthread库
linux·运维·开发语言·网络·c++·算法
麦德泽特5 分钟前
基于 Go 语言的 Modbus 项目实战:构建高性能、可扩展的工业通信服务器
服务器·开发语言·golang·modbus·rtu
sinat_255487819 分钟前
泛型·学习笔记
java·jvm·数据库·windows·python
还是大剑师兰特10 分钟前
pnpm format 什么作用
开发语言·javascript·ecmascript
QuZero13 分钟前
Java Synchronized principle
java·开发语言
明灯伴古佛17 分钟前
面试:Java中乐观锁的实现原理是什么
java·面试·职场和发展
单片机学习之路20 分钟前
【Python】输入input函数
开发语言·python