How to map a step definition to a feature file in Cucumber?

Rest AssuredDynamic ProgrammingProgramming

We can map a step definition file to a feature file in Cucumber. This can be done using the below steps −

Step1− Create a feature file with .feature extension(say Login.feature) with the following −

Feature − Login Module

Scenario − Welcome Page Login verification

Given User is on Welcome Page

Then Welcome page should be displayed

Step2− Create a step definition java file(say stepDefination.java) having the mapping of the step definition file to the feature file.

Example

package stepDefinations;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
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");
   }
}

Project Structure

raja
Updated on 22-Nov-2021 10:33:39

Advertisements