selenium - 如何从 Jenkins 重新执行失败的自动化场景
问题描述
我正在使用 maven 命令在 TestNG 框架中运行黄瓜测试。每天我都在执行 Jenkins 的测试用例并在 Jenkins 中生成黄瓜报告。(使用黄瓜报告插件)
我正在寻找一种解决方案来在 Jenkins 中重新运行失败的测试用例,它应该给出最终报告。
请为我提供实现这一目标的方法。
解决方案
一种简单的方法是,在 TestNG 中使用 IRetryAnalyzer。它将重新运行失败的测试用例。
在最终报告中,如果重新运行通过,那么我将显示为通过(最初失败一个显示为跳过)
如果重新运行也失败,则标记为失败。
例子:
public class Retry implements IRetryAnalyzer {
private int count = 0;
private static int maxTry = 3;
@Override
public boolean retry(ITestResult iTestResult) {
if (!iTestResult.isSuccess()) { //Check if test not succeed
if (count < maxTry) { //Check if maxtry count is reached
count++; //Increase the maxTry count by 1
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed
return true; //Tells TestNG to re-run the test
} else {
iTestResult.setStatus(ITestResult.FAILURE); //If maxCount reached,test marked as failed
}
} else {
iTestResult.setStatus(ITestResult.SUCCESS); //If test passes, TestNG marks it as passed
}
return false;
}
}
添加Testng.xml文件
您也可以添加测试
@Test(retryAnalyzer = Retry.class)
推荐阅读
- vue.js - 为什么我在 nuxt 中的“仅限客户端”组件抱怨“未定义窗口”?
- javascript - 多个条件下的 Google Apps 脚本中的 setnumberformat()(例如 xb) 基于引导令牌
- certificate - 尝试在 CACERTS 中更新 PFX 证书时出错
- c# - 在发送电子邮件时,MailKit 在 C# 中引发错误
- javascript - 如何在一页上运行两次 javascript/Canvas 脚本?
- sql - 如何将 postgres 12 生成的 sql 文件恢复到 postgres 9.6 数据库中
- python - python代码仅从gcs存储桶中读取部分csv文件
- session - 如何在 MVC .NET Core 2.2 的模型中使用 Session
- angular - 带有nestjs的Angular-universal:错误:找不到模块'./drivers/node-mongodb-native/connection'
- cordova - 通过 Ionic 4 上的硬件后退按钮关闭应用程序