Three Different Ways on Cucumber Runner
I have been working on Web automation projects. Generally, I prefer to use Cucumber due to providing behavior-driven development.
Every project needs a different approach for execution. We need a runner class for executing feature files, but which test framework is better to use with Cucumber? I have three different options, two with TestNG and one with JUnit. You can prefer as your project needs.
I’m listing from the simplest to the most complex ones.
- Cucumber Runner with JUnit
The first example is being created by Cucumber-JUnit and JUnit dependencies. I had been using it for an API project because I didn’t need TestNG annotation to perform it.
package myTestRunners; | |
import io.cucumber.junit.Cucumber; | |
import io.cucumber.testng.CucumberOptions; | |
import org.junit.AfterClass; | |
import org.junit.BeforeClass; | |
import org.junit.runner.RunWith; | |
@RunWith(Cucumber.class) | |
@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 TestRunnerWithJunit { | |
@BeforeClass | |
void beforeClass() { | |
} | |
@AfterClass | |
void afterClass() { | |
} | |
}
=============================================================================
2) Cucumber Runner with TestNG (AbstractTestNGCucumberTests) This example is being created by Cucumber-TestNG and TestNG dependencies. Using the advantages of TestNG, Test XML files can be created and feature files can be performed. We can execute more than one runner class by creating the XML file as concurrently. package myTestRunners; import io.cucumber.testng.AbstractTestNGCucumberTests; import io.cucumber.testng.CucumberOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; @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 TestRunner extends AbstractTestNGCucumberTests { @BeforeTest void beforeTest() { } @AfterTest void AfterTest() { } } =========================================================================== <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite thread-count="2" name="Example Project" parallel="tests"> <test name="TestRunner1"> <classes> <class name="myTestRunners.TestRunner" /> </classes> </test> <test name="TestRunner2"> <classes> <class name="myTestRunners.TestRunner" /> </classes> </test> </suite>=================================================================================3) Cucumber Runner with TestNG (IRetryAnalyzer) |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.