java - TestNG Reporting, how to quickly identify Retry-d Tests? -


hello: when @test fails , retry happens, there direct way in testng distinguish between test has been retried , test has not been retried - such through ng context method or variable?

  • case 1: if test not been retried 1st test test has not been retried.
  • case 2: if test has been retried 2 times 3rd test test has not been retried.

some options have found such http://www.seleniumeasy.com/testng-tutorials/retry-listener-failed-tests-count-update - wanted check if community has other means and/or recommendations.

you can try this. idea retrieve retry analyser instance associated particular test method , query retry count. if retry count greater zero, method retried.

import org.testng.assert; import org.testng.iretryanalyzer; import org.testng.itestcontext; import org.testng.itestresult; import org.testng.testlisteneradapter; import org.testng.annotations.listeners; import org.testng.annotations.test;  import java.util.hashset; import java.util.set; import java.util.concurrent.atomic.atomicinteger;  @listeners(identifyretriedtests.identifyinglistener.class) public class identifyretriedtests {     private static atomicinteger counter = new atomicinteger(0);     private static atomicinteger anothercounter = new atomicinteger(0);      @test(retryanalyzer = retry.class)     public void hello() {         if (counter.incrementandget() == 3) {             assert.asserttrue(true);         } else {             assert.fail();         }     }      @test(retryanalyzer = retry.class)     public void anotherhello() {         if (anothercounter.incrementandget() == 5) {             assert.asserttrue(true);         } else {             assert.fail();         }      }      public static class identifyinglistener extends testlisteneradapter {          @override         public void ontestsuccess(itestresult tr) {             iretryanalyzer retry = tr.getmethod().getretryanalyzer();             if (retry instanceof retry) {                 //check if retry analyser's retry count greater zero. if yes, retried method                 if (((retry) retry).getretrycount() > 0) {                     tr.setattribute("retried", true);                 }             }         }          @override         public void onfinish(itestcontext testcontext) {             set<itestresult> results = new hashset<>();             results.addall(testcontext.getfailedtests().getallresults());             results.addall(testcontext.getpassedtests().getallresults());             (itestresult result : results) {                 if (result.getattribute("retried") != null) {                     system.err.println(result.getmethod().getmethodname() + "() retried");                 }             }         }     }      public static class retry implements iretryanalyzer {         private atomicinteger retrycount = new atomicinteger(0);         private static int maxretrycount = 10;          public boolean retry(itestresult result) {             return retrycount.getandincrement() < maxretrycount;         }          int getretrycount() {             return retrycount.get();         }     } } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -