Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Cucumber Interview Questions and Answers

Ques 21. Explain the difference between Background and Hooks in Cucumber.

Background is used to define a set of common steps for all scenarios in a feature, while Hooks are blocks of code that run before or after specific events in the Cucumber execution cycle.

Example:

Feature: Online Shopping
  Background:
    Given a user is logged in
  Scenario: Add item to cart
    When the user adds an item to the cart
    Then the cart should display the item

Is it helpful? Add Comment View Comments
 

Ques 22. How can you reuse step definitions in Cucumber?

Step definitions can be reused by creating separate step definition files and then referencing those step definitions in the feature files using the 'glue' option in the test runner configuration.

Example:

glue = {"path.to.step.definitions"}

Is it helpful? Add Comment View Comments
 

Ques 23. What is the purpose of the 'Scenario Outline' Examples table header in Cucumber?

The Examples table header in Scenario Outline specifies the names of the variables that will be used in the scenario, and it helps map the values from the Examples table to the corresponding placeholders in the scenario steps.

Example:

Scenario Outline: Search with different keywords
    Given the user is on the search page
    When the user searches for 
    Then results should include 
    Examples:
      | keyword   | result           |
      | cucumber  | relevant results |
      | testing   | accurate results |

Is it helpful? Add Comment View Comments
 

Ques 24. What is the purpose of the 'But' keyword in Cucumber?

The 'But' keyword is used to provide an alternative step with additional clarification, often used after 'Given', 'When', or 'Then' for better readability.

Example:

Scenario: Login with valid credentials
    Given the user is on the login page
    When the user enters valid credentials
    Then the user should be logged in
    But the user dashboard should be displayed

Is it helpful? Add Comment View Comments
 

Ques 25. How do you organize feature files in a Cucumber project?

Feature files are typically organized based on the functionality they represent or by feature. A common approach is to create directories for each feature and place related feature files within those directories.

Example:

project
|-- src
|   |-- test
|       |-- java
|           |-- features
|               |-- login
|                   |-- login.feature
|               |-- search
|                   |-- search.feature

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2025 WithoutBook