What are the main file components in Cucumber?


The main file components in Cucumber are listed below −

  • Feature file − This file has an extension of .feature. It comprises single or multiple test scenarios in plain text. All the scenarios are written with the keywords like Then, Given, When, And, But, Feature, Background and so on.

Example

Feature file.

Feature: Login Test
Scenario: Tutorialspoint login validation
Given: Launch the “https://www.tutorialspoint.com/index.htm”
  • Step Definition File - This file has an extension of .java. It provides mapping of the test scenarios to the test script logic.

Example

Step Definition file based on the above feature file.

@Given (“^Launch the \"([^\"]*)\"$”)
public void launch_application(String url){
   System.out.println("The url is : " + url);
}
  • Test Runner file - This file has an extension of .java. It acts as a link between the step definition file and feature file. It gives the option of selecting a single or multiple feature files. It has the path of the step definition file and the feature file.

Example

Test Runner file

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(
   features = "src/test/java/features",
   glue="stepDefinations")
public class TestRunner extends AbstractTestNGCucumberTests { }

Updated on: 11-Jun-2020

617 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements