Quality Testing

Quality is delighting customers

How to re-run failed test cases in selenium webDriver ?

Hello,

I am new to this site. I am posting my first query.

How to re-run failed test cases in Selenium WebDriver?

Views: 900

Reply to This

Replies to This Discussion

Thanks for your reply.

If you want to rerun failed scripts. Just add failed scripts in suite and run again.

Using TestNG framework and little changes to the XML file we can rerun all failed scripts without much effort.

We can use TestNG class and specify the failed_test.xml path to the TestNG to run the failed test cases. For more details, View below link:

https://www.youtube.com/watch?v=kaUJgNyLaKs

Just select the select the recorrected and recompiled failed test script from the project explorer of the eclipse IDE and right click the Mose button,select run as Testng option from various options shown after right clicking the mouse.
You should able to Rerun/Reexecute the Failed Test Script and after the run/execution completion the you have to select the relevant Testing Report XML file which will available in the project explore section, select the Testing Report File and open the file, it will show the Test Summary Report with the details of Pass/Failed results of all your test cases run under the Test Suite selected for the run, you can verify the results of the failed test cases too, the above scenario works when the entire Test suite is selected for the rerun/rexecution which includes the rerun of the failed Test cases also.

However there is one another option wherein you can select the specific recreated and recompiled failed test case/test cases from the project explorer of the Eclipse IDE and right click the mouse you can select run as TestNg option and as usual after the rerun/reexecution of the selected test cases you, as usual as I mentioned previously you will be provided with Test Summary Report in XML under the project Explore option and open the XML Report, now you can only the details of Pass/Failed results of the selected rerun/ rexecuted test cases only.
Note: Anytimes Even when you are Rerunning/ Reexecuting your corrected Failed Test Cases, it is mandatory that test cases are compiled every time when changes are made and there should not be any compilation errors without which the execution/rerun will not happen for the corrected test cases and if there exists a fault in your corrected test script,it will only show compilation errors and it will not rexecuted/ rerun by the TestNg with no results available in the TestNg Summary XML Report.

Hope I was able to give you an answer and let me know your inputs after using the above approach given by me to address your query.

Hello,

Normally in automation after executing scripts/tests, we will check for the results and if the test fails because of above reasons we will re-run then again.

Instead of that we can ask Selenium/testNG to execute the failed test cases again for X (we can define) number of times and check for the updated results.

To achieve this we need to implement TestNG IRetryAnalyzer.

you will find detailed coding here 

hi

once check this site www.karthikelearn.com, to get more idea about selenium webdriver

Hi most of the test automation services implemented the retry logic using  TestNG IRetryAnalyzer. Below is code that will automatically rerun the failed scripts using the testng report.

Create 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;
    }
}
 
Class RetryListener
package com.pack.test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import org.testng.IAnnotationTransformer;
import org.testng.IRetryAnalyzer;
import org.testng.annotations.ITestAnnotation;

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);
        }

    }
}

Add the listener in testng.xml file

<listeners>
        <listener class-name="com.pack.test.RetryListener"/>
  </listeners>

Hope this will help you in implementing the retry logic

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2017   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service