Programmatically run failed testng tests.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Programmatically run failed testng tests.

Pavan Kumar-2
I have implemented logic to run dependent failed tests to run automatically based on threshold. Would like to contribute to the testng-repo. to have this utility which would definitely benefit all of us. How can I do this? Please guide me.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically run failed testng tests.

Krishnan Mahadevan
This should get you started https://github.com/cbeust/testng/blob/master/CONTRIBUTING.md

On Thu, Apr 19, 2018, 10:26 Pavan Kumar <[hidden email]> wrote:
I have implemented logic to run dependent failed tests to run automatically based on threshold. Would like to contribute to the testng-repo. to have this utility which would definitely benefit all of us. How can I do this? Please guide me.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically run failed testng tests.

Nael Abd eljawad
In reply to this post by Pavan Kumar-2
You can add Retry Listener:

Retry Class:

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 1;

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

/*
* 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
* @see org.testng.IRetryAnalyzer#retry(org.testng.ITestResult)
*/
@Override
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;
}

And add this listener:

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

}

You have 2 options to call above listener:

  1. From your xml testng runner as bellow:
    <listeners>
    <listener class-name="package path....com.listeners.RetryListener" />
    <listener class-name="org.uncommons.reportng.HTMLReporter" />
    <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
    </listeners>


  2. From the test class:
    @Listeners({ package path....com.listeners.RetryListener })
    You need to add above declaration before the class declaration.  

On Thursday, 19 April 2018 07:56:31 UTC+3, Pavan Kumar wrote:
I have implemented logic to run dependent failed tests to run automatically based on threshold. Would like to contribute to the testng-repo. to have this utility which would definitely benefit all of us. How can I do this? Please guide me.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.