Testing / Cucumber Interview Questions
What is the purpose of Given, When, Then in Cucumber scenarios?
Given, When, and Then structure a scenario into three conceptual parts: establishing context, performing an action, and observing an outcome. And and But continue whichever of the three sections precedes them, avoiding repetitive keyword use for multiple steps in the same category.
Scenario: withdrawing within the available balance Given an account with a balance of 100 When the customer withdraws 40 Then the balance should be 60 And a withdrawal receipt should be issued
Functionally, Cucumber treats all these keywords identically at runtime: it matches the step text against step definitions regardless of which keyword precedes it, so Given and When steps are technically interchangeable from the engine's point of view. The distinction exists entirely for human readability, making a scenario's structure (setup, action, verification) clear at a glance to anyone reading it, technical or not.
More Related questions...