当前位置:网站首页>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
边栏推荐
- Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
- navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
- log4j-slf4j-impl cannot be present with log4j-to-slf4j
- 优化查询(工作中)
- JPA Native Query(本地查询)及查询结果转换
- 2022-08-03 oracle执行慢SQL-Q17对比
- 网络基础学习系列四(网络层,数据链路层和一些其他重要协议或技术)
- Golang第一章:入门
- 【云原生实用技巧】使用 skopeo 批量同步 helm chart 依赖镜像
- MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
猜你喜欢

win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改

一些思考:腾讯股价为何持续都低
![[b01lers2020]Life on Mars](/img/d0/d5c9b7224542c8843ce29adc7ef713.png)
[b01lers2020]Life on Mars

老板:公司系统太多,能不能实现账号互通?

【开源框架】国内首个通用云计算框架,任意程序都可做成云计算。

【MySQL进阶】数据库与表的创建和管理

七夕快乐!

全球观之地理部分

Zilliz 2023 秋季校园招聘正式启动!

Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
随机推荐
Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
九种方式,教你读取 resources 目录下的文件路径
嵌入式系统:时钟
pikachu Over permission 越权
mysql如何将表结构导出到excel
易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
【bug】汇总Elipse项目中代码中文乱码解决方法!
HCIP BGP实验报告
override学习(父类和子类)
On the Qixi Festival of 2022, I will offer 7 exquisite confession codes, and at the same time teach you to quickly change the source code for your own use
Research status of target detection at home and abroad
Embedded Systems: GPIO
关于Yii2批量更新的操作
Canvas App中点击图标生成PDF并保存到Dataverse中
utils timer
HDU 5655 CA Loves Stick
如何创建一个Web项目
Why do we need callbacks
node连接mysql数据库报错:Client does not support authentication protocol requested by server
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?