Udemy REST Assured free

Cucumber with Java: Features & Feature File

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.

A feature consist of list of scenarios to be tested for that feature. Keyword to represent a feature under test is "Feature".

Feature File: A file in which we store features, feature description and scenarios to be tested. The extension of feature file should be ".feature".  For each functionality there should be separate feature file.

In feature file you describe your test in Descriptive language like English, French etc. In Cucumber, Feature file contains Business requirement. 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 small description of the feature beneath the feature title in the feature file. This will fulfil the need of a good documentation as well.

Example of Feature and Scenario inside Feature file

@tag
Feature: Title of your feature
  This is description of Feature

  #This is sample scenario
  @tag1
  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

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

How to create Feature file in Cucumber

There can be several methods to create feature file, below are steps to create feature file using eclipse IDE.

Create Cucumber feature file using Eclipse IDE

Step 1: On your feature file folder. Right click and select New->File. If File option is not available in New then you will find it in General section of popup which appear when you click on New ->Other.

file in eclipse general

Step 2: Click Next button and enter filename as anyFeatureName.feature. You can choose file name of your choice but you have to save it with extension .feature.

Step 3: Click Finish

Video Tutorial: Cucumber Features & Feature File