I'm working with the cucumber, testng project and integrated the latest cucumber into that. If I use TestNg annotations in my runner class they will execute fine. But if I use cucumber annotations in my runner class it will not execute. So I'm confusing why and looking for a reason for that.
Below code block 'tearDown' method does not execute after I execute the 'TestCases' class. feature file executes without any issue till the end but the '@AfterStep' method does not execute. Any issue in my dependencies or?
Since I use cucumber 5.7.0 with testng '@AfterStep' is import under
'import io.cucumber.java.AfterStep;'
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import io.cucumber.java.AfterStep;
public class TestCases extends AbstractTestNGCucumberTests {
@CucumberOptions(
plugin = {"pretty",
"html:target/cucumber-html-report",
"json:target/cucumber-report.json"},
features = {"src/test/resources/featureFiles/",},
glue = {"com.tests.testSteps"},
tags = {"@regressiontest"})
@AfterStep
public void tearDown() {
System.out.println("========= This line not executing ===========");
}
}
POM file configuration as below:
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>5.7.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>5.7.0</version>
</dependency>
</dependencies>
May be you should put @AfterStep in step definitions . I tested it with cucumber-java
6.9.1 and it works fine . However, I am using it with junit
. My pom
looks like this
<junit.version>4.13.1</junit.version>
<cucumber.version>6.9.1</cucumber.version>
...
...
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
Make your runner file different than step definition. This is my runner file
@RunWith(Cucumber.class)
@CucumberOptions
(
plugin = {
"pretty",
"json:target/AcceptanceTestResults.json"
},
features = "src/test/resources/com/test/RestAssured.feature",
glue = {"com.test.stepdefs"}
)
public class AcceptanceIT {
}
And then put your step defs in a diff class
public class RestAssuredIT {
....
....
@AfterStep // this imports from io.cucumber:cucumber-java:6.9.1
public void afterEveryStep(){
//this prints after each step in feature file
System.out.println("***after every step****");
}
}