当前位置:网站首页>Testng listener
Testng listener
2022-08-03 22:27:00 【qq_492448446】
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="API" parallel="none">
<listeners>
<listener class-name="com.welab.automation.framework.listener.RetryListener"></listener>
</listeners>
<test verbose="2" preserve-order="true" name="channel">
<classes>
<class name="com.welab.automation.projects.channel.runners.MobileTestRunner_iOS">
<methods>
<include name="runScenario"/>
</methods>
</class>
</classes>
</test>
</suite>
import com.welab.automation.framework.uils.PropertiesReader;
import org.testng.ITestResult;
import org.testng.util.RetryAnalyzerCount;
public class TestRetryAnalyzer extends RetryAnalyzerCount {
private static int count =1;
public TestRetryAnalyzer() {
super.setCount(count);
}
@Override
public boolean retryMethod(ITestResult result) {
return true;
}
public void reSetCount() {
super.setCount(count);
}
}
import com.welab.automation.framework.utils.entity.api.JsonEntity;
import com.welab.automation.framework.utils.entity.api.TestCaseUtils;
import org.testng.*;
import org.testng.annotations.ITestAnnotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class RetryListener extends TestListenerAdapter implements IAnnotationTransformer,IHookable {
public void transform(
ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
IRetryAnalyzer iRetryAnalyzer = annotation.getRetryAnalyzer();
if (iRetryAnalyzer == null) {
annotation.setRetryAnalyzer(TestRetryAnalyzer.class);
}
}
@Override
public void onFinish(ITestContext testContext) {
Iterator<ITestResult> listOfSkippedTests =
testContext.getSkippedTests().getAllResults().iterator();
while (listOfSkippedTests.hasNext()) {
ITestResult skippedTest = listOfSkippedTests.next();
ITestNGMethod method = skippedTest.getMethod();
if (testContext.getFailedTests().getResults(method).size() > 0
|| testContext.getPassedTests().getResults(method).size() > 0) {
skippedTest.setStatus(0);
listOfSkippedTests.remove();
}
}
}
//iHookable重写方法run
@Override
public void run(IHookCallBack iHookCallBack, ITestResult iTestResult) {
JsonEntity jsonEntity = getJsonEntity(iTestResult);
Map<String, List<String>> sqlExpression = null;
//replace parameter
if (jsonEntity != null) {
jsonEntity.setJsonObject(TestCaseUtils.replaceParameter(jsonEntity.getJsonObject()));
jsonEntity.updateHeader();
}
//execute test case
iHookCallBack.runTestMethod(iTestResult);
}
public JsonEntity getJsonEntity(ITestResult testResult) {
JsonEntity jsonEntity = null;
Object[] parameters = testResult.getParameters();
if (parameters.length > 0) {
for (Object parameter : parameters) {
if (parameter instanceof JsonEntity) {
jsonEntity = (JsonEntity) parameter;
}
}
}
return jsonEntity;
}
@Override
public void onTestFailure(ITestResult result) {
TestRetryAnalyzer testRetryAnalyzer = (TestRetryAnalyzer) result.getMethod().getRetryAnalyzer();
testRetryAnalyzer.reSetCount();
}
}
IHookable Listener provides a similar toAOP的方式,对测试methodTo surround the programming.主要的应用场景:
1. Dynamic to rewrite the testmethod (Replace test method is empty running)
2. Dynamically decide whether to skip the testmethod (例如鉴权)
3. 自定义注解,例如@ignore, When detected with the annotation,Skip the test execution
边栏推荐
- Shell编程的条件语句
- 中国企业构建边缘计算解决方案的最佳实践
- 嵌入式系统:时钟
- noip preliminary round
- The sword refers to the offer question 22 - the Kth node from the bottom in the linked list
- Data_web(八)mysql增量同步到mongodb
- CAS:1620523-64-9_Azide-SS-biotin_biotin-disulfide-azide
- October 2019 Twice SQL Injection
- Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
- 云平台建设解决方案
猜你喜欢

云平台建设解决方案

113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself

Data_web(九)mongodb增量同步到mongodb

Bytebase数据库 Schema 变更管理工具

21天打卡挑战学习MySQL——《MySQL工具的使用》第一周 第二篇
![navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication](/img/09/a579c60e07cdc145175e72673409f7.png)
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication

override学习(父类和子类)

Flutter 桌面探索 | 自定义可拖拽导航栏

Data_web(八)mysql增量同步到mongodb

Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记
随机推荐
Summary bug 】 【 Elipse garbled solution project code in Chinese!
How to write a database document management tool based on WPF (2)
Codeup刷题笔记-简单模拟
举一个 web worker 的例子
UVa 10003 - Cutting Sticks(白书,区间DP)
Bytebase数据库 Schema 变更管理工具
LabVIEW代码生成错误 61056
【刷题篇】二叉树的右视图
L2-041 插松枝
mysql如何将表结构导出到excel
[N1CTF 2018] eating_cms
一些思考:腾讯股价为何持续都低
Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
2022-08-02 mysql/stonedb慢SQL-Q18-内存使用暴涨分析
HCIP BGP实验报告
Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
Flink--Join以及Flink函数
Nine ways to teach you to read the file path in the resources directory
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
UVa 437 - The Tower of Babylon (White Book)