</>

Technology

Cucumber

Difficulty

Beginner

Interview Question

What is meant by a feature file in Cucumber?

Answer

Feature File in Cucumber

A feature file is the core component of Cucumber BDD testing. It contains test scenarios written in Gherkin language and acts as both executable test specification and living documentation.

Properties of a Feature File

  • Extension: .feature
  • Location: src/test/resources/features/
  • Written in plain English (Gherkin)
  • Contains one Feature and multiple Scenarios
  • Maximum recommended: 10 scenarios per feature file

Structure of a Feature File

Gherkin
Feature: User Registration
  As a new user
  I want to register on the website
  So that I can access premium features

  Background:
    Given the user is on the registration page

  Scenario: Register with valid details
    When the user enters name "John Doe"
    And the user enters email "john@test.com"
    And the user enters password "Pass@123"
    And the user clicks Register
    Then the success message "Registration Successful" should appear

  Scenario: Register with existing email
    When the user enters email "existing@test.com"
    And the user clicks Register
    Then the error "Email already registered" should appear

Rules

  1. First line must start with Feature: keyword
  2. One Feature per .feature file
  3. A feature file can have multiple Scenario blocks
  4. Background steps run before every scenario in the file

Directory Structure

CODE
src/
  test/
    resources/
      features/
        login.feature
        registration.feature
        checkout.feature

Follow AutomateQA

Related Topics