How to run tests using a test runner file for Cucumber?

We can run tests using a test runner file for Cucumber. The test runner file should contain the path of the feature file and step definition file that we want to execute.

Code Implementation of the Feature file

Feature − Login Module

Scenario Welcome Page Login verification

Given User is on Welcome Page

Then Welcome page should be displayed


Code Implementation of step definition file

package stepDefinations;
public class stepDefination {
   @Given("^User is on Welcome Page$")
   public void user_on_welcome_page() {
      System.out.println("User on welcome page");
   @Then("^Welcome page should be displayed$")
   public void verify_user_on_welcome_page() {
      System.out.println("User should be on welcome page");

Code Implementation of test runner file

package cucumberOptions;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
   //path of feature file
   features = "src/test/java/features/Login.feature",
   //path of step definition file
   glue = "stepDefination"
public class TestRunner {

Project Structure

Updated on: 22-Nov-2021

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started