Skip to main content

Feature File in Cucumber

How to Create Feature File in Cucumber

There can be several methods to create a feature file, below are steps to create a feature file using eclipse IDE. You can organize your feature file in a folder or subfolder depending on the modules on your project.

Create a Cucumber feature file using Eclipse IDE

  1. On your feature file folder, right-click and select New->File. If the File option is not available in New, you will find it in the General section of the popup, which appears when you click on New ->Other.
  2. Click the Next button and enter the filename as anyFeatureName.feature. You can select the file name of your choice, but you have to save it with extension .feature.
  3. Click Finish

Cucumber Feature File Example

This is the sample feature file generated by Cucumber Eclipse Plugin. If the plugin is not installed on your system, you will get a pop to install the plugin. You can follow the steps here to install Cucumber Eclipse Plugin or Natural Plugin.

#Sample Feature Definition Template
Feature: Title of your feature
  I want to use this template for my feature file

  Scenario: Title of your scenario
    Given I want to write a step with precondition
    And some other precondition
    When I complete action
    And some other action
    And yet another action
    Then I validate the outcomes
    And check more outcomes

  Scenario Outline: Title of your scenario outline
    Given I want to write a step with <name>
    When I check for the <value> in step
    Then I verify the <status> in step

      | name  | value | status  |
      | name1 |     5 | success |
      | name2 |     7 | Fail    |

The text that immediately follows the Feature keyword is the title of the Feature file. In the above example, lines starting with # are comments. Word, where @ is prefixed, are tags. The above example contains one scenario and one scenario outline. Feature files can contain either a Scenario or Scenario outline or a combination of them. Example search.feature, registration.feature etc.The names for the Scenarios and Feature files must be unique. A feature file is an entry point to the cucumber tests.

What is Feature File in Cucumber?

A file in which we store features, feature descriptions, and scenarios to be tested. It also contains tags, rules, and background associated with scenarios. For each functionality, there should be a separate feature file.

In the feature file, you describe your test in Descriptive language like English, French, etc. In Cucumber, the Feature file contains Business requirements. It is an essential part of Cucumber, as it serves as an automation test script as well as live documents.

The suggested best practice is to write a short description of the feature beneath the feature title in the feature file. This will fulfill the need for good documentation as well.

What is Cucumber Feature?

A feature can be defined as a standalone unit or functionality of a project. Each independent functionality of the project under test can be termed as a feature. Each feature file has one feature section. You will get errors if you try to add more than one feature section in a file. 

A feature consists of a list of scenarios to be tested for that feature. The keyword to represent a feature under test is "Feature."

All other Components Scenario, Scenario outline, Background, and Rules, are part of this Feature section only. It consists of its own tag, and that tag is inherited by its components.

Video Tutorial: Feature File in Cucumber

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.