All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.javasbar.framework.testng.reporters.TimeoutRetryAnalyzer Maven / Gradle / Ivy

Go to download

DolphinNG provides set of very useful addons for testNG. Most important features that it supports are condensed smart reports, auto creation of jira ticets for test failures, linking test fails to jira tickets, progress reporting during test runs.

There is a newer version: 1.3.0
Show newest version
package com.javasbar.framework.testng.reporters;

import com.javasbar.framework.lib.common.IOUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.IRetryAnalyzer;
import org.testng.ITestNGListener;
import org.testng.ITestResult;

public class TimeoutRetryAnalyzer implements IRetryAnalyzer, ITestNGListener
{
    private static final Logger LOG = LogManager.getLogger(TimeoutRetryAnalyzer.class);
    private int retryCount = 0;
    private int maxRetryCount;

    /**
     * If a testcase is failed and if baseUrl is not pingable, retry the test case.
     */
    @Override
    public boolean retry(ITestResult testResult)
    {
        LOG.info("@EnvAwareRetryAnalyzer retry");
        String maxRetryStr = (String) testResult.getTestContext().getAttribute("maxRetryCount");
        if (null != maxRetryStr)
        {
            try
            {
                maxRetryCount = Integer.valueOf(maxRetryStr);
            } catch (NumberFormatException e)
            {
                e.printStackTrace();
                maxRetryCount = 3;
            }
        } else
        {
            maxRetryCount = 3;
        }

        if (!testResult.isSuccess() && (retryCount++ < maxRetryCount))
        {
            String message = testResult.getThrowable().getMessage().toLowerCase();
            if (message.contains("time-out"))
            {
                LOG.info("Retrying for time out... ");
                return true;
            }
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy