3

I have a suite which consists of 2 test cases. When I run this suite, the results should be 1 passed and 1 failed.

When I am trying to run the failed test cases through TestNG-failed.xml file, it is executing the both testcases instead of failed test case. I referred the TestNG-failed.xml which is having the both passed and failed test cases mentioned under the test tag.

I want to execute only failed test cases. Please help me to do this.

  • What test framework do you use? Please provide more and accurate info. – masood ghz Oct 27 '15 at 14:49
  • I am using testng+maven+selenium webdriver – QAMember Oct 28 '15 at 4:58
  • can you add a copy of your TestNG-failed.xml? It sounds like it may be malformed. If, for example you misnamed a class to run, the default behavior is to run all classes/methods. – ECiurleo Oct 29 '15 at 14:22
  • Is your failed test case depending on any other method? – Robben Nov 4 '15 at 19:52
0

your TestNG-failed.xml can be formed similar to the following to run specific (subset of) tests

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="webapp-webdriver" verbose="8" data-provider-thread-count="7" parallel="tests" thread-count="7">

    <test name="webapp-webdriver" preserve-order="true">    
        <parameter name="browser" value="firefox"/>
        <classes>
            <class name="org.your.pagetests.ClassName">
                <methods>
                    <include name="TestName"/>
                    <include name="TestName2"/>
                </methods>
            </class>
        </classes>  
    </test>
</suite>
0

You can use the IRetryAnalyzer interface provided by testng for this. Using this you can retry your failed test cases multiple times till it passes. In the below example Ithe max retry count is set to 1.

public class Retry implements IRetryAnalyzer{


    int retryCount =0;

    int maxRetryCount = 1;


    public boolean retry(ITestResult result) {

        // TODO Auto-generated method stub

        if(retryCount < maxRetryCount){

                System.out.println("Retrying test with "+result.getName()+" with status "+

                        getResultStatusName(result.getStatus()));

                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;

    }




}


public class RetryListner implements IAnnotationTransformer{


    public void transform(ITestAnnotation annotation, Class testClass,

            Constructor testConstructor, Method testMethod) {

        // TODO Auto-generated method stub

        IRetryAnalyzer analyzer = annotation.getRetryAnalyzer();


        if(analyzer ==null){

            annotation.setRetryAnalyzer(Retry.class);

        }

    }




}

And add the listener to the testng.xml

<listener 

     class-name="com.listeners.RetryListner">

        </listener> 
-1

please follow this url in which You have to refresh the Project and then you can see for faild.xml file right click on that re run the fail test. http://www.softwaretestingmaterial.com/run-failed-test-cases-using-testng/

  • This smells like spam somehow but maybe it's just the feel of the linked blog site. This is essentially a link-only answer. If you have something to add to the existing answers, please add more detail to your answer and include a more complete summary of the post you are linking to. Your answer should be able to stand on its own even if the link breaks in the future. – c32hedge Dec 5 '17 at 16:03
  • It certainly seems to fit the proper material, so I think this is simply low quality, not spam. Shekhar, please edit the important information and material into the post, in case the link ever goes down. Thanks! – corsiKa Dec 5 '17 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.