Feature Keyword

 

Feature Keyword in Cucumber Framework

In the Cucumber framework, the Feature keyword is used to define a high-level business requirement that the application must fulfill. It represents the functionality that will be tested and consists of one or more Scenarios written in Gherkin syntax.


Syntax of Feature Keyword

Feature: <Feature Name>  
  Description: <Brief explanation of the feature>  
  Scenario: <Scenario Name>  
    Given <Precondition>  
    When <Action>  
    Then <Expected Result>  

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

Example 1: User Login Feature

Feature: User Login Functionality  
  As a registered user  
  I want to log in to the application  
  So that I can access my account  

  Scenario: Successful Login  
    Given the user is on the login page  
    When the user enters a valid username and password  
    And clicks on the login button  
    Then the user should be redirected to the homepage  

Explanation:
  • The Feature describes the login functionality.
  • The Scenario specifies a test case for successful login.
  • The Given, When, And, Then steps define the test flow.
===========================================================

Example 2: Feature with Multiple Scenarios

Feature: Payment Processing Scenario: Successful Payment Given the user is on the payment page When the user enters valid payment details And clicks on the "Pay Now" button Then the system should confirm the payment Scenario: Failed Payment Due to Insufficient Balance Given the user is on the payment page When the user enters payment details with insufficient balance And clicks on the "Pay Now" button Then the system should display an "Insufficient Balance" error Explanation: The Feature covers the entire payment processing functionality. Each Scenario defines a specific test case.

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

Example 3: Feature: Credit Card Payment End-to-End Flow in Cucumber Framework

Here is a well-structured Cucumber Feature file for an end-to-end Credit Card Payment flow using Gherkin syntax:
Feature: Credit Card Payment End-to-End Flow 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 Insufficient Funds Given the user is on the credit card payment page When the user enters a card with insufficient balance And clicks on the "Pay Now" button Then the payment should be declined And an "Insufficient Balance" error 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: Payment with Minimum Due Amount Given the user is on the credit card payment page When the user enters valid card details And selects the "Minimum Due Amount" option And clicks on the "Pay Now" button Then the payment should be processed for the minimum due amount And a payment confirmation 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: Defines the Credit Card Payment process. Background: Ensures the user is logged in before each scenario runs. Scenarios: Successful Payment Payment Failures (Insufficient Funds, Invalid Card) Minimum Due Payment Scenario Outline: Covers multiple card types in one scenario using Examples.