Executing Cucumber tests using Cucumber class

To write the tests using JUnit @RunWith annotation, we need below dependencies.
cucumber.api.junit.Cucumber – This class is present in the cucumber-junit artifact library.

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>



<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
</dependency>

Then you can add below test class. After running the below test, cucumber generates the report at target/selenium-reports. Cucumber.class contains main method that reads the feature file and executes scenario in it.

package org.softpost;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "classpath:abc.feature",
        glue = "classpath:org.softpost",
        plugin = "html:target/selenium-reports"
)

public class MyTests {
}

You may also like...