Cucumber Interview Hub

Review these commonly asked Cucumber interview questions with concise, clear answers.

1. What is Cucumber?

Answer: Cucumber is a Behavior Driven Development (BDD) tool that allows writing test scenarios in a human-readable format so that technical and non-technical stakeholders can understand them.

2. What is BDD in Cucumber?

Answer: BDD (Behavior Driven Development) is an approach where application behavior is defined using examples written in plain language before development and testing begin.

3. What language is used to write Cucumber test cases?

Answer: Cucumber uses Gherkin, a plain-text language that follows the Given-When-Then format.

4. What is a Feature file?

Answer: A Feature file is a text file with a .feature extension that contains business scenarios written in Gherkin syntax.

5. What are Given, When, and Then keywords?

Answer:

  • Given: Precondition or initial state
  • When: Action performed by the user
  • Then: Expected outcome

6. What is a Scenario in Cucumber?

Answer: A Scenario represents a single test case that describes a specific business behavior of the application.

7. What is Scenario Outline?

Answer: Scenario Outline allows running the same scenario multiple times using different test data provided in an Examples table.

8. What are Step Definitions?

Answer: Step Definitions are Java methods that map Gherkin steps to executable code using annotations like @Given, @When, and @Then.

9. What is the use of Background keyword?

Answer: Background is used to define common preconditions that are executed before each scenario in a feature file.

10. What is the role of Hooks in Cucumber?

Answer: Hooks are used to execute setup and teardown code before or after scenarios using @Before and @After annotations.

11. What is Gherkin?

Answer: Gherkin is a business-readable language used in Cucumber to write feature files. It helps bridge communication between technical and non-technical stakeholders.

12. What is the Examples table used for?

Answer: The Examples table provides multiple sets of test data for a Scenario Outline, allowing the same scenario to run multiple times with different inputs.

13. What is the difference between Scenario and Scenario Outline?

Answer:

  • Scenario: Executes once with fixed data
  • Scenario Outline: Executes multiple times using data from the Examples table

14. What is a Tag in Cucumber?

Answer: Tags are used to organize, filter, and control scenario execution (e.g., @smoke, @regression).

15. How do you execute tagged scenarios in Cucumber?

Answer: By configuring tags in the test runner file using the tags attribute.

16. What is a Test Runner class?

Answer: A Test Runner class connects feature files and step definitions and controls test execution using frameworks like JUnit or TestNG.

17. What is Cucumber Dry Run?

Answer: Dry Run checks whether all Gherkin steps have corresponding step definitions without executing the test cases.

18. What is the purpose of Cucumber Reports?

Answer: Cucumber Reports provide detailed execution results showing passed, failed, and skipped scenarios in a readable format.

19. How do you share data between steps in Cucumber?

Answer: Data can be shared using instance variables, dependency injection (like PicoContainer), or scenario context classes.

20. What is the difference between Cucumber and TestNG?

Answer:

  • Cucumber: Focuses on behavior and business-readable tests
  • TestNG: Focuses on test execution control, assertions, and reporting

21. What is a Cucumber Glue Code?

Answer: Glue code connects feature files and step definitions. It specifies the package location where Cucumber should look for step definition classes.

22. What is a Cucumber Runner with TestNG?

Answer: A Cucumber Runner with TestNG allows executing Cucumber scenarios using TestNG features like parallel execution, grouping, and advanced reporting.

23. What is the purpose of @BeforeStep and @AfterStep hooks?

Answer: These hooks execute before and after each step in a scenario and are commonly used for logging, screenshots, or step-level validation.

24. What is a DataTable in Cucumber?

Answer: A DataTable allows passing structured test data from feature files to step definitions in tabular format.

25. What is the difference between DataTable and Examples table?

Answer:

  • DataTable: Used within a single scenario
  • Examples table: Used with Scenario Outline to run multiple iterations

26. What is Cucumber Expressions?

Answer: Cucumber Expressions are an alternative to regular expressions used to define step patterns in a more readable and maintainable way.

27. What is the use of @CucumberOptions?

Answer: @CucumberOptions is used to configure feature paths, glue paths, tags, plugins, and dry-run settings in the runner class.

28. How do you handle parallel execution in Cucumber?

Answer: Parallel execution is handled using TestNG or JUnit configuration combined with Cucumber options and thread-safe WebDriver management.

29. What is a Scenario Context in Cucumber?

Answer: Scenario Context is a custom mechanism used to share data across steps within the same scenario without using global variables.

30. How do you integrate Cucumber with CI/CD tools?

Answer: Cucumber is integrated with CI/CD tools like Jenkins by configuring build jobs to execute tests, generate reports, and publish results automatically.