mardi 20 janvier 2015

retryAnalyzer with dependsOnGroups

I have Selenium tests that every once in a while fail, so I want a retryAnalyzer to force the tests to rerun. Now I'm adding some tests dependencies with dependsOnGroups. But if a selenium test fails and passes the second time, the test depending on it will be skipped.


What I want is testRetryAndPass passes once (regardless of it being a retry or not), then I want testDependOnGroup to run. Right now testDependOnGroup is skipped.


The test code:



@Test(dependsOnGroups = "test")
public void testDependOnGroup()
{
assertTrue( true );
}

@Test( groups = { "test" }, retryAnalyzer = RetryAnalyzer.class )
public void testRetryAndPass()
{
if ( RetryAnalyzer.retryCount == 0 )
{
assertTrue( false );
}
else
{
assertTrue( true );
}
}


RetryAnalyzer:



public class RetryAnalyzer extends TestListenerAdapter implements IRetryAnalyzer
{
private static Logger logger = Logger.getLogger( RetryAnalyzer.class );

public static int retryCount = 0;
public static final int MAX_RETRIES = 1;

@Override
public boolean retry( ITestResult result )
{
logger.info( "Running retry for " + result.getMethod() );
boolean retryFunction = false;
if ( retryCount < MAX_RETRIES )
{
retryCount++;
retryFunction = true;
}

return retryFunction;
}
}


I will gladly answer any questions you may have.


Aucun commentaire:

Enregistrer un commentaire