Feature Request: Support for 'Or' Step Following a 'Then' Step in Gherkin for Alternative Outcome Assertion #2284
Replies: 2 comments 4 replies
-
|
The problem here is the procedurality (?), of the gherkin. What you are saying here is you want to do something conditional. If it's a conditional setup, then you should absorb this into your setup. One "ruby" example is for instance If it's conditional execution, i.e. actions. Then you should alter your behaviour accordingly. And should probably test these different permutations. A scenario outline is likely your best call here If it's conditional assertions, then you should absorb that into your library. RSpec (Ruby), has a nice syntax for this.
Hope this gives some insight. |
Beta Was this translation helpful? Give feedback.
-
|
@abhinandraj07 Maybe a single step with data table can suite for this case? Scenario: User receives confirmation after payment
Given the user has completed a purchase
When the user pays using a supported payment gateway
Then the user should see one of the success messages:
| Payment successful |
| Transaction completed |
| Your payment has been processed | |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
💡 Feature Idea: Support for
OrStep Following aThenStep in GherkinProblem Statement
In real-world systems, a single action may lead to one of several valid outcomes. Currently, Gherkin syntax does not support expressing alternative expected outcomes within a single scenario. This forces test authors to duplicate scenarios with identical
GivenandWhensteps, which:Proposed Solution
Introduce support for an
Orstep that can follow aThenstep to express alternative expected outcomes.Example Syntax
Scenario: Payment confirmation message validation
Given the user has completed a purchase
When the user pays using a supported payment gateway
Then the user should see "Payment successful"
Or the user should see "Transaction completed"
Or the user should see "Your payment has been processed"
The Or step is valid only after a Then step
It represents an alternative expected outcome
Execution Logic
Step Evaluation
Group the initial Then step and subsequent Or steps as a logical block.
Evaluate steps in order:
Short-Circuit Behavior
Reporting Terminology
✅ Passed | The step matched and executed successfully.
⚠️ Unmet | The step did not match, but the scenario continued due to Or logic.
⏭ Bypassed | The step was skipped because a previous Or step passed.
Example Report
Case 1: First step passes
✅ Then the user should see "Payment successful" (Passed)
⏭ Or the user should see "Transaction completed" (Bypassed)
⏭ Or the user should see "Your payment has been processed" (Bypassed)
✅Scenario PASSED: One of the valid outcome matched
Case 2: Second step passes
✅ Or the user should see "Transaction completed" (Passed)
⏭ Or the user should see "Your payment has been processed" (Bypassed)
✅Scenario PASSED: One of the valid outcome matched
Case 3: No step matches
❌ Scenario FAILED: No valid outcome matched
Benefits
Backward Compatibility
🤝 Contribution
Happy to collaborate on prototyping or implementations.
Open to feedback and suggestions from the community!
Beta Was this translation helpful? Give feedback.
All reactions