For my internship, I have to use TestNG and selenium to test the web application. But I have a problem, sometimes selenium or the Browser does not work for some random reason, so the working test is marked as "failure". To avoid this, I can use the annotation @Test(invocationCount = 4, successPercentage = 25), and then, if the test passes once, the test will be marked as "Success", this is good, but the problem is that this solution multiplies the testing time by 4, it is not very effective.
What I can do to reduce the testing time is to write some rule "if the test failed, repeat this test (and only if the test did not work), and if it worked the second, third or fourth time, then mark this test as" successful "Therefore, I can avoid these random errors. But I did not find how to write this rule, I saw that we can add a listener, so we have a method called" onTestFailure", so I can do something when the test failed fail, but I don’t know how to repeat the test.
I also found testng-failed.xml where all failed tests were saved, so we can run this xml file to run these tests again, but this will remove the report from the previous first run, but I want the tests to be marked as “successful” if the second launch is successful. (I have included testNG / selenium in Jenkins, so I have a graph with all the tests, so this method is not very adapted, but this method does not multiply the test time by 4, and this is what I want)
So, if you have any clue how to do this, it would be very nice.