实际上,与testng-failed.xml相关的问题已经被问了很多次了,但我的问题几乎没有什么不同。我想一起运行所有失败的测试用例,所以我所做的是在我的pom中传递了testng-failed.xml。
但我面临的问题是,首先我的testng.xml会运行,然后是testng-failed.xml,然后它会被覆盖。因此,假设我对我的测试用例进行了第二次新的运行,testng.xml运行,那么我的testng-failed.xml之前已经失败了测试用例,所以它运行之前失败的用例,然后用这次失败的用例更新testng-failed.xml。
我不知道应该添加哪个侦听器来处理这个问题:每当我第一次运行testng.xml时,它都应该运行,然后它应该覆盖testng-failed.xml,然后testng-failed.xml应该运行。我使用的是Maven、selenium、testng。
我只是在我的pom中输入了testng-failed.xml,如下所示。请让我知道要使用哪个listner
<suiteXmlFiles>
<suiteXmlFile>src/resources/testng/testng.xml</suiteXmlFile>
<suiteXmlFile>test-output/testng-failed.xml</suiteXmlFile>
</suiteXmlFiles>
发布于 2015-08-19 11:28:33
通过实现“IAnnotationTransformer”创建类“RetryListener”。
public class RetryListener implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation testannotation, Class testClass,
Constructor testConstructor, Method testMethod) {
IRetryAnalyzer retry = testannotation.getRetryAnalyzer();
if (retry == null) {
testannotation.setRetryAnalyzer(Retry.class);
}
}
}
现在创建另一个类。
public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 1;
// Below method returns 'true' if the test method has to be retried
else 'false'
//and it takes the 'Result' as parameter of the test method that just
ran
public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
System.out.println("Retrying test " + result.getName() + " with status "
+ getResultStatusName(result.getStatus()) + " for the " + (retryCount+1) + " time(s).");
retryCount++;
return true;
}
return false;
}
public String getResultStatusName(int status) {
String resultName = null;
if(status==1)
resultName = "SUCCESS";
if(status==2)
resultName = "FAILURE";
if(status==3)
resultName = "SKIP";
return resultName;
}
}
现在,在您的testNG xml文件中添加以下行
<listeners>
<listener class-name="com.pack.test.RetryListener"/>
</listeners>
并且不在pom.xml中传递Xml文件
希望它能起作用
谢谢
发布于 2015-08-19 18:48:59
为什么在同一个testng任务中运行testng xml和失败的测试xml。您应该分离构建任务,首先运行testng并生成失败的测试xml,然后另一个任务运行失败的测试xml。看起来不错。
发布于 2018-12-22 19:34:28
我实现了运行一次,然后只重新运行三次新失败的测试。
mvn $par1=$pSuiteXmlFile test > $test1log
mvn $par1=$failedRelPath test > $failed1log
mvn $par1=$failedRelPath test > $failed2log
mvn $par1=$failedRelPath test > $failed3log
它是有效的,但测试用例很少。我有一个包含300个测试的套件,不知何故,在主(第一次)运行后,surefire/testng没有创建testng-failed.xml。当套件较小时,将根据需要创建testng-failed.xml。
https://stackoverflow.com/questions/32088383
复制相似问题