Problem with IRetryAnalyzer regarding the results of the tests

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

Problem with IRetryAnalyzer regarding the results of the tests

Tsiakos, Panagiotis
Hi,
I have implemented two classes( RetryListener and  Analyzer) in order
to reexecute a failed test twice. From this perspective it works fine
but I am facing the following problem:
I want to have the first test result as skipped.For this reason in
Analyzer class I had set  arg0.setStatus(ITestResult.SKIP);
Nevertheless I always take the result as fail.
I also observed that the following annotation combination @Test
(priority=0,successPercentage=50,retryAnalyzer=Analyzer.class) does
not work in the concept that if that test methods executes twice, the
first time is failed and the second is passed I always take 1 passed
and 1 failed test.In the same scenarion if I use the combination
@Test (priority=0,successPercentage=50,invocationCount = 2) I take1
passed test. So it seems that there is some problem in the
IRetryAnalyzer .From what I have seen this problem with the results is
a known issue. Any idea why this happens? Should it be a fix for that
issue? I am using the latest testng (6.0.1)

Thank you in advance

Panagiotis

@Test (priority=0,successPercentage=50,retryAnalyzer=Analyzer.class)

public void test2() throws InterruptedException

{


System.out.println("\n\n");

System.out.println("I am the second\n");

Thread.sleep(2000);

SuperHelper.noWindowLoaded = true;

// if(SuperHelper.invocationsCount == 0)

Reporter.log("<font color=\"#FF00FF\"/>"+message+"</font><br>\n");

test++;

if(test==1)

throw new InterruptedException();


}







package com.helper;


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 {


@SuppressWarnings("unchecked")

@Override

public void transform(ITestAnnotation arg0, Class arg1, Constructor
arg2,Method arg3) {

IRetryAnalyzer retry = arg0.getRetryAnalyzer();

if (retry==null){

arg0.setRetryAnalyzer(Analyzer.class);

}

}


}




package com.helper;


import org.testng.IRetryAnalyzer;

import org.testng.ITestResult;

import com.Seleniumhelper.SeleniumWebdriver;


public class Analyzer implements IRetryAnalyzer {


public static int MAX_RETRY_COUNT = 1;

private int count = 0;

String message = "First failure,the test will be executed once more";

@Override

public boolean retry(ITestResult arg0) {

count++;

if(count <= MAX_RETRY_COUNT && SuperHelper.noWindowLoaded ){

arg0.setStatus(ITestResult.SKIP);

SeleniumWebdriver.LOGGER.info("\t"+message);

SuperHelper.noWindowLoaded = false;

return true;

}

return false;


}


}

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Problem with IRetryAnalyzer regarding the results of the tests

shankarkc78@gmail.com
please check if this post helps you
I had similar problem and solved it by calling remove on failed result before rerunning.

On Friday, May 6, 2011 3:00:58 PM UTC+5:30, tsak wrote:
Hi,
I have implemented two classes( RetryListener and  Analyzer) in order
to reexecute a failed test twice. From this perspective it works fine
but I am facing the following problem:
I want to have the first test result as skipped.For this reason in
Analyzer class I had set  arg0.setStatus(ITestResult.SKIP);
Nevertheless I always take the result as fail.
I also observed that the following annotation combination @Test
(priority=0,successPercentage=50,retryAnalyzer=Analyzer.class) does
not work in the concept that if that test methods executes twice, the
first time is failed and the second is passed I always take 1 passed
and 1 failed test.In the same scenarion if I use the combination
@Test (priority=0,successPercentage=50,invocationCount = 2) I take1
passed test. So it seems that there is some problem in the
IRetryAnalyzer .From what I have seen this problem with the results is
a known issue. Any idea why this happens? Should it be a fix for that
issue? I am using the latest testng (6.0.1)

Thank you in advance

Panagiotis

@Test (priority=0,successPercentage=50,retryAnalyzer=Analyzer.class)

public void test2() throws InterruptedException

{


System.out.println("\n\n");

System.out.println("I am the second\n");

Thread.sleep(2000);

SuperHelper.noWindowLoaded = true;

// if(SuperHelper.invocationsCount == 0)

Reporter.log("<font color=\"#FF00FF\"/>"+message+"</font><br>\n");

test++;

if(test==1)

throw new InterruptedException();


}







package com.helper;


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 {


@SuppressWarnings("unchecked")

@Override

public void transform(ITestAnnotation arg0, Class arg1, Constructor
arg2,Method arg3) {

IRetryAnalyzer retry = arg0.getRetryAnalyzer();

if (retry==null){

arg0.setRetryAnalyzer(Analyzer.class);

}

}


}




package com.helper;


import org.testng.IRetryAnalyzer;

import org.testng.ITestResult;

import com.Seleniumhelper.SeleniumWebdriver;


public class Analyzer implements IRetryAnalyzer {


public static int MAX_RETRY_COUNT = 1;

private int count = 0;

String message = "First failure,the test will be executed once more";

@Override

public boolean retry(ITestResult arg0) {

count++;

if(count <= MAX_RETRY_COUNT && SuperHelper.noWindowLoaded ){

arg0.setStatus(ITestResult.SKIP);

SeleniumWebdriver.LOGGER.info("\t"+message);

SuperHelper.noWindowLoaded = false;

return true;

}

return false;


}


}

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/cOEeZYiqy9cJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.