Skip to main content
Added few more details. Regards
Source Link

This is effectively useful if we implement and use in scripts. #ValueAddition. There are multiple reasons why the test fails:

  1. Due to application downtime.
  2. Due to the network issue.
  3. Due to loading issue and etc.

But if the script is failing due to xpath and some valid reason then you have to maintain for re work on your scripts.

Solution -

package TestNGDemo;
 
import org.testng.IRetryAnalyzer;
 
import org.testng.ITestResult;
 
// implement IRetryAnalyzer interface
 
public class Retry implements IRetryAnalyzer{
 
      // set counter to 0
 
       int minretryCount=0;
 
      // set maxcounter value this will execute our test 3 times             
 
      int maxretryCount=2;
 
      // override retry Method
 
       public boolean retry(ITestResult result) {

            // this will run until max count completes if test pass within this frame it will come out of for loop
 
              if(minretryCount<=maxretryCount)
 
              {
                   // print the test name for log purpose   
 
                     System.out.println("Following test is failing===="+result.getName());
 
                   // print the counter value    
 
                     System.out.println("Retrying the test Count is=== "+ (minretryCount+1));
 
                   // increment counter each time by 1  
                     minretryCount++;
                     return true;
              }
              return false;
       }
}

specify this in the test case -

@Test(retryAnalyzer=Retry.class)

Hope it helps you !

This is effectively useful if we implement and use in scripts. #ValueAddition. There are multiple reasons why the test fails:

  1. Due to application downtime.
  2. Due to the network issue.
  3. Due to loading issue and etc.

But if the script is failing due to xpath and some valid reason then you have to maintain for re work on your scripts.

Solution -

package TestNGDemo;
 
import org.testng.IRetryAnalyzer;
 
import org.testng.ITestResult;
 
// implement IRetryAnalyzer interface
 
public class Retry implements IRetryAnalyzer{
 
      // set counter to 0
 
       int minretryCount=0;
 
      // set maxcounter value this will execute our test 3 times             
 
      int maxretryCount=2;
 
      // override retry Method
 
       public boolean retry(ITestResult result) {

            // this will run until max count completes if test pass within this frame it will come out of for loop
 
              if(minretryCount<=maxretryCount)
 
              {
                   // print the test name for log purpose   
 
                     System.out.println("Following test is failing===="+result.getName());
 
                   // print the counter value    
 
                     System.out.println("Retrying the test Count is=== "+ (minretryCount+1));
 
                   // increment counter each time by 1  
                     minretryCount++;
                     return true;
              }
              return false;
       }
}

specify this in the test case -

@Test(retryAnalyzer=Retry.class)

Hope it helps you !

This is effectively useful if we implement and use in scripts. #ValueAddition. There are multiple reasons why the test fails:

  1. Due to application downtime.
  2. Due to the network issue.
  3. Due to loading issue and etc.

But if the script is failing due to xpath and some valid reason then you have to maintain for re work on your scripts.

Solution -

package TestNGDemo;
 
import org.testng.IRetryAnalyzer;
 
import org.testng.ITestResult;
 
// implement IRetryAnalyzer interface
 
public class Retry implements IRetryAnalyzer{
 
      // set counter to 0
 
       int minretryCount=0;
 
      // set maxcounter value this will execute our test 3 times             
 
      int maxretryCount=2;
 
      // override retry Method
 
       public boolean retry(ITestResult result) {

            // this will run until max count completes if test pass within this frame it will come out of for loop
 
              if(minretryCount<=maxretryCount)
 
              {
                   // print the test name for log purpose   
 
                     System.out.println("Following test is failing===="+result.getName());
 
                   // print the counter value    
 
                     System.out.println("Retrying the test Count is=== "+ (minretryCount+1));
 
                   // increment counter each time by 1  
                     minretryCount++;
                     return true;
              }
              return false;
       }
}

Hope it helps you !

Source Link

This is effectively useful if we implement and use in scripts. #ValueAddition. There are multiple reasons why the test fails:

  1. Due to application downtime.
  2. Due to the network issue.
  3. Due to loading issue and etc.

But if the script is failing due to xpath and some valid reason then you have to maintain for re work on your scripts.

Solution -

package TestNGDemo;
 
import org.testng.IRetryAnalyzer;
 
import org.testng.ITestResult;
 
// implement IRetryAnalyzer interface
 
public class Retry implements IRetryAnalyzer{
 
      // set counter to 0
 
       int minretryCount=0;
 
      // set maxcounter value this will execute our test 3 times             
 
      int maxretryCount=2;
 
      // override retry Method
 
       public boolean retry(ITestResult result) {

            // this will run until max count completes if test pass within this frame it will come out of for loop
 
              if(minretryCount<=maxretryCount)
 
              {
                   // print the test name for log purpose   
 
                     System.out.println("Following test is failing===="+result.getName());
 
                   // print the counter value    
 
                     System.out.println("Retrying the test Count is=== "+ (minretryCount+1));
 
                   // increment counter each time by 1  
                     minretryCount++;
                     return true;
              }
              return false;
       }
}

specify this in the test case -

@Test(retryAnalyzer=Retry.class)

Hope it helps you !