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

结果

相关推荐
Ivy_belief几秒前
C++新特性汇总:涵盖C++11到C++23
java·c++·c++11·c++23
码界奇点4 分钟前
基于Python与GitHub Actions的正方教务成绩自动推送系统设计与实现
开发语言·python·车载系统·自动化·毕业设计·github·源代码管理
哈哈哈笑什么6 分钟前
Spring Boot接口国际化异常信息方案
java·spring boot·后端
qq_162987696 分钟前
SpringBoot框架选型
java·spring boot·后端
爱学习的小可爱卢14 分钟前
JavaEE进阶-SpringBoot三层架构:餐厅模式解析
java·java-ee
kaikaile199517 分钟前
MATLAB计算卫星星下点轨迹
开发语言·算法·matlab
掉鱼的猫17 分钟前
Java 低代码平台的“动态引擎”:Liquor
java·低代码·groovy
二狗哈1 小时前
Cesium快速入门15:图元Primitive创建图像物体
开发语言·javascript·3d·webgl·cesium·地图可视化
TT哇1 小时前
【Database Navigator 插件】idea 社区版连接 mysql 数据库
java·数据库·mysql·intellij-idea·database
lljss20201 小时前
C# 定时器类实现1s定时器更新UI
开发语言·c#