TestNG - Failed retry
来源:互联网 发布:givens变换例题矩阵论 编辑:程序博客网 时间:2024/06/06 05:32
TestNG - Failed retry
TestNG - Failed retry
作者: Max.Bai
时间: 2015/01
TestNG 失败重跑功能
1. 创建自己的IRetryAnalyzer
重写retry 方法,获得xml设置的重跑次数,判断失败次数小于重跑次数是返回true
import org.testng.IRetryAnalyzer;import org.testng.ITestResult;public class TestRetryAnalyzer implements IRetryAnalyzer {private static final String TEST_RETRY_COUNT = "testRetryCount";private int currentTry = 0;private int m_maxRetries = 0;public TestRetryAnalyzer() {currentTry=0;m_maxRetries=3;}public int getCount() {return this.currentTry;}public int getMaxCount() {return this.m_maxRetries;}@Overridepublic synchronized boolean retry(ITestResult result) {String maxRetriesStr = result.getTestContext().getSuite().getParameter("maxRetries"); if(maxRetriesStr != null) { try { m_maxRetries = Integer.parseInt(maxRetriesStr); System.out.println("Get failed Retry count from xml:" + m_maxRetries); } catch (final NumberFormatException e) { System.out.println("NumberFormatException while parsing maxRetries from suite file." + e); } }String testClassName = String.format("%s.%s", result.getMethod().getRealClass().toString(),result.getMethod().getMethodName()); if ( !result.isSuccess() ) { if ( currentTry < m_maxRetries ) { ++currentTry; System.out.println( "[RETRYING] " + testClassName + " FAILED, " + "Retrying " + currentTry + " time"); return true; } } currentTry=0; return false;}}
2. 添加自己的IRetryAnalyzer到测试用例
有两种方法:
1. 设置用例或者测试类的listener添加失败重跑IRetryAnalyzer listener
2. 添加自己的IAnnotationTransformer,重写transform方法,添加listener到testng的xml
当用例执行时修改用例的注解,添加自己的重跑IRetryAnalyzer listener
public class RetryListener implements IAnnotationTransformer {@SuppressWarnings("rawtypes")@Overridepublic void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,Method testMethod) {IRetryAnalyzer retry = annotation.getRetryAnalyzer();if (retry == null) { annotation.setRetryAnalyzer(TestRetryAnalyzer.class);}}}
3. 注册自己的监听器
在testng.xml中添加step1 and step2 中自己的监听器
<listeners> <listener class-name="Test.RetryListener" /> </listeners>
4. 添加重跑次数设置
在testng.xml中添加重跑参数
<parameter name="maxRetries" value="1"/>
失败重跑用例总数会增加,慎用。
0 0
- TestNG - Failed retry
- 实现testNg的retry机制
- 如何解决TestNG Retry的问题
- 关于使用testng的retry问题
- TestNG
- testng
- testng
- TestNG
- TestNG
- TestNG
- TestNG
- testng
- TestNG
- testNG
- TestNG
- Webdriver take screen shot when case failed use TestNG
- Webdriver take screen shot when case failed use TestNG
- FATAL: DTM initialization: failure during startup recovery, retry failed, check segment status (cdb
- UIViewController内存警告管理
- JS中utf8和GBK的字符编码转换
- error C2099: initializer is not a constant
- Xargs
- URI和URL的区别
- TestNG - Failed retry
- 使用OpenSSL API 建立SSL安全通信的一般流程
- cocos2dx粒子编辑器软件:mac推荐Particle designer/win推荐ParticleEditor
- 上海传智Java学员追随梦想,一路向东
- 数据挖掘之无监督学习篇
- 如何成为一名无坚不摧的开发者
- mysql分区分表的概念
- Linux之V4L2基础编程
- build, debug, compile and run