关于使用testng的retry问题
总体是利用TestNG里面的IRetryAnalyzer、TestListenerAdapter接口来实现相关问题
1、定义一个自己的retryanalyzer
import org.testng.ITestResult;
import org.testng.util.RetryAnalyzerCount;
//这里集成自抽象类RetryAnalyzerCount,该抽象类实现了IRetryAnalyzer
public class TestRetryAnalyzer extends RetryAnalyzerCount{
public TestRetryAnalyzer(){
setCount(1);
}
@Override
public boolean retryMethod(ITestResult arg0) {
// TODO Auto-generated method stub
return true;
}
}
2、定义自己的监听器,集成自TestListenerAdapter
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.testng.IResultMap;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.TestListenerAdapter;
import org.testng.ITestNGMethod;
import org.testng.collections.Lists;
import org.testng.collections.Objects;
public class RetryTestListener extends TestListenerAdapter {
private List<ITestNGMethod> m_allTestMethods =
Collections.synchronizedList(Lists.<ITestNGMethod>newArrayList());
private List<ITestResult> m_passedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
private List<ITestResult> m_failedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
private List<ITestResult> m_skippedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
private List<ITestResult> m_failedButWSPerTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
private List<ITestContext> m_testContexts= Collections.synchronizedList(new ArrayList<ITestContext>());
private List<ITestResult> m_failedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList());
private List<ITestResult> m_skippedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList());
private List<ITestResult> m_passedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList());
public synchronized void onTestFailure(ITestResult arg0) {
m_allTestMethods.add(arg0.getMethod());
m_failedTests.add(arg0);
}
@Override
public void onFinish(ITestContext context) {
for(int i=0;i<context.getAllTestMethods().length;i++){
System.out.println("~~~~~~~~~~"+context.getAllTestMethods()[i].getCurrentInvocationCount());
if(context.getAllTestMethods()[i].getCurrentInvocationCount()==2){
System.out.println("~~~~~~~~~~~~~~~~~"+context.getAllTestMethods()[i].getParameterInvocationCount());
System.out.println(context.getAllTestMethods()[i].ignoreMissingDependencies());
if
(context.getFailedTests().getResults(context.getAllTestMethods()[i]).size()
== 2 ||
context.getPassedTests().getResults(context.getAllTestMethods()[i]).size()
== 1){
context.getFailedTests().removeResult(context.getAllTestMethods()[i]);
}
}
}
}
...
}
3、在测试申明中说明使用retry
@Test(retryAnalyzer = TestRetryAnalyzer.class)
4、加入一个我们自己的监听器
public class RetryTest {
public static void main(String args[]){
TestNG tng = new TestNG();
RetryTestListener rtl = new RetryTestListener();
XmlSuite xs = new XmlSuite();
Parser parser = new Parser("./testxml/temp.xml");
List<XmlSuite> suites = new ArrayList<XmlSuite>();
try {
suites = parser.parseToList();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
};
tng.setXmlSuites(suites);
tng.addListener(rtl);
tng.run();
}
}
关于使用testng的retry问题的更多相关文章
- testng执行用例失败,再次执行
我们通过重写testng的retry方法和transform方法来实现用例失败重跑的功能. 首先添加两个文件 TestngRetry.java public class TestngRetry imp ...
- java-testng-selenium优化
由于项目中webui测试的需要,是用testng+selenium的方式,其中遇到过几个问题,记录下,方便以后查看 1.重复运行多次case 因为是selenium,所以有的时候需要运行多次,方法是写 ...
- testNG retry 失败的testcase只需要在xml中配置一个listener即可
问题情况 先说下问题情况,最近在做testNG与selenium集成做自动化测试的问题. 因为如果将t ...
- testng跑失败用例重试
testng 提高用例通过率,失败用例要重新运行一次 步骤: 1.新建一个Retry 类,implements IRetryAnalyzer接口,这个类里面确定重跑次数,以及分析每次失败是否需要重新运 ...
- testng实现场景恢复
自动化测试过程中存在很多的不稳定性,例如网络的不稳定,浏览器无响应等等,这些失败往往并不是产品中的错误.那么这时我们需要对执行失败的场景恢复重新执行,确认其是否确实失败. 以前使用QTP的时候也使用了 ...
- TestNG监听器实现用例运行失败自动截图、重运行功能
注: 以下内容引自 http://blog.csdn.net/sunnyyou2011/article/details/45894089 (此非原出处,亦为转载,但博主未注明原出处) 使用Testng ...
- testng增加失败重跑机制
注: 以下内容引自 http://www.yeetrack.com/?p=1015 testng增加失败重跑机制 Posted on 2014 年 10 月 31 日 使用Testng框架搭建自动测试 ...
- testng优化:失败重跑,extentReport+appium用例失败截图,测试报告发邮件
生成的单html方便jenkins集成发邮件,= = 构建失败发邮件 参考:https://blog.csdn.net/galen2016/article/details/77975965 步骤: 1 ...
- TestNg失败重试机制
TestNg提供了失败重试接口IRetryAnalyzer,需要实现retry方法: package com.shunhe.testngprac.retry; import org.testng.IR ...
随机推荐
- POJ 1961 循环节
和POJ 2406 几乎一样.前者是求 该字符串的最小的循环节.也就是最大的循环次数.后者是求该字符串的每个前缀的循环节的最大循环次数.(如果有的话).而且必须大于1.才可以输出.就是POJ 2406 ...
- jquery分页滑动插件(鼠标可控制上下滑动)
这个插件非常好用 http://www.swiper.com.cn/
- bzoj2759
题解: lct+解线性方程组 首先先把每一个环搞出来,然后再建立一个额外的点 然后解方程.. 代码: #include <bits/stdc++.h> using namespace st ...
- 有效二叉查找树判断(java实现)
leetcode 原题 :(即判断二叉树是否为二叉查找树) Given a binary tree, determine if it is a valid binary search tree (BS ...
- 『转』Emsisoft Anti-Malware 8刷Key教程 - 文字版
先分主机和客机,下载好 EAM8安装包 和 30天重置工具EAM Trial Reset 1.1.exe 1. 主机安装 Emsisoft Anti-Malware 8 并激活30天试用版 如果已 ...
- EM算法及其应用: K-means 与 高斯混合模型
EM算法及其应用(一) EM算法及其应用(二): K-means 与 高斯混合模型 上一篇阐述了EM算法的主要原理,这一篇来看其两大应用 -- K-means 与 高斯混合模型,主要由EM算法的观点出 ...
- specialized English for automation-Lesson 1 Analog Amplifiers
要求每天阅读一篇技术文档,不需要记下来,只是能看懂就好..后发现,这就是专业英语的课程资料. ----------------------------------------------------- ...
- react 拖拽排序---原生
定义css, 两个动画 .drag-up { -webkit-animation: dragup ease 0.2s 1; animation: dragup ease 0.2s 1; -webkit ...
- python切片取值和下标取值时,超出范围怎么办?
可迭代对象下标取值超出索引范围,会报错:IndexError 可迭代切片取值超出索引范围,不报错,而是返回对应的空值. a=[1,2,3,4] a[99] Traceback (most recent ...
- 0基础小白怎么学好Java?
自身零基础,我们应该先学好Java,小编给大家介绍一下Java的特性: Java语言是简单的 Java语言的语法与C语言和C++语言很接近,使得大多数程序员很容易学习和使用Java.Java丢弃了C+ ...