Below is the code for same:
1) Create a class with your rerun logic
Using the below logic you can immediate rerun your failed test case.
package com.companyName.web.utils;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class Retry implements IRetryAnalyzer{
private int retryCount = 0;
private int maxRetryCount = 3;
public boolean retry(ITestResult result) {
if(retryCount < maxRetryCount) { retryCount++; return true; } return false; } }
2) use below annotation in your test program
@Test(groups="groupName",retryAnalyzer=Retry.class)
if you are not using group then use this
@Test(retryAnalyzer=Retry.class)
Thanks! Good trick to avoid that many false positives!
ReplyDeletehi,do you know how to configure this listener in the test suite so i no need to add the annotation in every test ?
ReplyDeleteIAnnotationTransformer
Deleteit do not work fine in tesng 6.1.1
ReplyDeleteYou can try from here. It is provided with working sample.
ReplyDeletehttp://easytestautomation.blogspot.in/2015/06/selenium-rerun-failed-test-scripts.html