Created
March 30, 2022 20:19
-
-
Save burcuakkayaa/25a160ed83b83146d1190922f1029a55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myTestRunners; | |
import io.cucumber.testng.*; | |
import org.testng.IRetryAnalyzer; | |
import org.testng.ITestResult; | |
import org.testng.annotations.*; | |
@CucumberOptions( | |
features = "src/test/resources/functionalTests", | |
glue= {"myStepDefinitions" , "myHooks"}, | |
tags = "@chrome", | |
plugin = { "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:", | |
"timeline:test-output-thread/", | |
"rerun:src/test/resources/failedrerun.txt"}, | |
monochrome = true, | |
publish = true | |
) | |
public class TestRunnerWithRetry implements IRetryAnalyzer { | |
private TestNGCucumberRunner testNGCucumberRunner; | |
private int count = 0; | |
private static int maxTry = 3; | |
@Override | |
public boolean retry(ITestResult iTestResult) { | |
if (!iTestResult.isSuccess()) { ; | |
if (count < maxTry) { | |
count++; | |
iTestResult.setStatus(ITestResult.FAILURE); | |
return true; | |
} else { | |
iTestResult.setStatus(ITestResult.FAILURE); | |
} | |
} else { | |
iTestResult.setStatus(ITestResult.SUCCESS); | |
} | |
return false; | |
} | |
@BeforeClass(alwaysRun = true) | |
public void setUpClass() throws Exception { | |
System.out.println("Before Scenario ****"); | |
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass()); | |
} | |
@Test(groups = "cucumber", description = "Runs Cucumber Scenarios", | |
dataProvider = "scenarios",retryAnalyzer = TestRunnerWithRetry.class) | |
public void scenario(PickleWrapper pickleEvent, FeatureWrapper cucumberFeature) { | |
testNGCucumberRunner.runScenario(pickleEvent.getPickle()); | |
} | |
@DataProvider | |
public Object[][] scenarios() { | |
return testNGCucumberRunner.provideScenarios(); | |
} | |
@AfterClass(alwaysRun = true) | |
public void tearDownClass() { | |
System.out.println("After Scenario ****"); | |
testNGCucumberRunner.finish(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment