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

结果

相关推荐
二月夜15 分钟前
剖析Java正则表达式回溯问题
java·正则表达式
xuhaoyu_cpp_java1 小时前
项目学习(三)分页查询
java·经验分享·笔记·学习
想吃火锅10051 小时前
【leetcode】405.数字转换为十六进制数js
开发语言·javascript·ecmascript
程序员二叉1 小时前
【Java】集合面试全套精讲|HashMap/ArrayList高频考点完整版
java·面试·哈希算法
专注VB编程开发20年1 小时前
AI 生成C# WinForm 窗体 = 目前就是垃圾
开发语言·人工智能·c#
cfm_29141 小时前
JVM GC垃圾回收初步了解
java·开发语言·jvm
心之伊始2 小时前
LangChain4j RAG 实战:Java 后端如何把本地文档接入 Embedding 检索链路
java·架构·源码分析·csdn
~小先生~2 小时前
Python从入门到放弃(一)
开发语言·python
许彰午2 小时前
17_synchronized关键字深度解析
java·开发语言
z落落2 小时前
C# 泛型接口和泛型类+泛型约束
开发语言·c#