Feature File

Feature File in Cucumber Framework

  • In Cucumber Framework, a Feature file is a text file written in Gherkin syntax, which describes the application's behavior in a business-readable format. 
  • It contains one or more scenarios that define different functionalities of the application.
  • It acts as a Test Suite which consists of all scenarios.
  • We can simply create feature file with .feature extension.

Structure of a Feature File

Feature: Describes the functionality being tested.
Background (Optional): Common preconditions for all scenarios.
Scenario: Defines a single test case with a specific condition.
Scenario Outline (Optional): Used for data-driven testing.
Given, When, Then, And, But: Keywords used to define steps.

===============================================================

Example: Credit Card Payment Feature File

Feature: Credit Card Payment Processing  
  As a registered user  
  I want to make a payment using my credit card  
  So that I can complete my transaction successfully  

 Background:  
    Given the user is logged into the payment portal  

 Scenario: Successful Credit Card Payment  
    Given the user is on the credit card payment page  
    When the user enters valid card details  
    And selects the full payment option  
    And clicks on the "Pay Now" button  
    Then the payment should be processed successfully  
    And a payment confirmation message should be displayed  


Scenario: Payment Failure Due to Invalid Card Details  
    Given the user is on the credit card payment page  
    When the user enters an invalid credit card number  
    And clicks on the "Pay Now" button  
    Then the payment should be declined  
    And an "Invalid Card Details" error message should be displayed  


Scenario Outline: Payment Attempt with Different Card Types  
    Given the user is on the credit card payment page  
    When the user enters "<CardType>" card details  
    And selects the full payment option  
    And clicks on the "Pay Now" button  
    Then the payment should be "<PaymentStatus>"  


Examples:  
      | CardType   | PaymentStatus |  
      | Visa       | processed     |  
      | MasterCard | processed     |  
      | Amex       | declined      |  
      | Expired    | declined      |  
  
  
Explanation:
✅ Feature: Describes Credit Card Payment Processing.
✅ Background: Ensures the user is logged in before each scenario runs.
✅ Scenario: Defines specific test cases (e.g., successful and failed payments).
✅ Scenario Outline: Used for data-driven testing, with Examples for different card types.

===============================================================

Where to Place the Feature File?

Store it inside the src/test/resources/features/ folder in a Cucumber Selenium framework.
The Feature file should be linked to Step Definitions written in Java (or any other supported language).