Skip to content

Create BDD Scenarios in Gherkin with AI

Test DesignUpdated 2026-10-21basic
TL;DR

Reads a user story and returns Cucumber-compatible Gherkin scenarios covering happy path, error scenarios, and at least two edge cases. Uses Scenario Outline with Examples tables when 2+ data variations exist. Forbids UI implementation detail in Then steps.

When to use it

  • You have a user story (As a... I want... So that...) and need first-draft acceptance tests.
  • You're moving a feature into a BDD workflow (Cucumber, SpecFlow, Behat) and need scaffolds.
  • You want a shared-language artifact between PM, dev, and QA before development starts (3 amigos).
  • You need to expand thin acceptance criteria into testable scenarios.

The prompt

XML-tagged: works best with Claude
create-bdd-scenarios.claude.mdprompt
<role>You are a BDD practitioner with 5+ years writing Gherkin for Cucumber projects. You write scenarios that read like business language, never like UI scripts.</role> <context>The team uses Cucumber with step definitions in TypeScript. Scenarios live in .feature files. We follow these rules: Given describes state, When describes a single user action, Then describes observable outcome (never UI implementation). We use Scenario Outline + Examples table when 2+ data variations exist.</context> <task>Convert the user story below into 4-6 Gherkin scenarios covering:1. The happy path (one scenario)2. At least one error/negative scenario3. At least two edge cases (boundary, race, unusual input)4. Use Scenario Outline + Examples whenever the same flow has 2+ data variations</task> <input>User story: {user_story}Acceptance criteria (if any): {acceptance_criteria}Out-of-scope constraints (if any): {constraints}</input> <constraints>- Gherkin keywords: Feature, Scenario, Scenario Outline, Background (only if 3+ scenarios share state), Given, When, Then, And, But.- Then steps describe observable outcomes: NEVER UI implementation ("button is blue", "modal slides in").- When steps describe ONE action; chain via "And" only if it's the same user intent.- Use Scenario Outline + Examples for data variations, never copy-paste scenarios with different inputs.- Tags: prefix the Feature with @feature-name; tag negative scenarios with @negative.</constraints> <output_format>A single .feature file as a code block, followed by a 1-2 sentence "Notes" paragraph listing any out-of-scope items the user might want to test in a separate feature.</output_format> <approach>Before writing, identify which steps are reusable across scenarios (Background candidates).</approach>

Example

Input
User story:
As a registered user
I want to reset my password
So that I can regain access if I forget it

Acceptance criteria:
- Reset link expires after 1 hour
- Reset link is single-use
- Three failed reset attempts in 10 minutes triggers rate limiting
Output
```gherkin
@password-reset
Feature: Password reset

  Background:
    Given I am a registered user with email "user@example.com"

  Scenario: Reset password with a valid link
    When I request a password reset
    And I open the reset link within 1 hour
    And I submit a new password "NewPass123"
    Then I am redirected to the login page
    And I can sign in with the new password

  @negative
  Scenario: Reset link expired
    Given I requested a password reset 70 minutes ago
    When I open the reset link
    Then I see a "Link expired" message
    And no password change is performed

  @negative
  Scenario: Reset link already used
    Given I already reset my password using the link
    When I open the same reset link again
    Then I see a "Link already used" message

  @negative
  Scenario Outline: Rate limiting on reset attempts
    Given I have made <previous_attempts> failed reset attempts in the last 10 minutes
    When I attempt another reset
    Then the request <outcome>

    Examples:
      | previous_attempts | outcome                         |
      | 0                 | succeeds                        |
      | 2                 | succeeds                        |
      | 3                 | is rejected with rate-limit msg |
      | 5                 | is rejected with rate-limit msg |

  @negative
  Scenario: An older reset link stops working after a newer request
    Given I requested a password reset, then immediately requested another one
    When I open the first reset link
    Then I see a "Link no longer valid" message
    And the second reset link still lets me complete the reset
```

Notes: Email deliverability, password complexity rules (covered by a separate signup feature), and account-lockout-from-failed-logins are out of scope of this feature.

Common pitfalls

  • Model often leaks UI detail into Then ('I see a red error banner'): keep the no-UI-language constraint.
  • Without acceptance criteria, edge cases default to generic 'invalid input' rather than scenario-specific (rate limit, race).
  • Background is over-used when only 1-2 scenarios actually share state: review whether it improves readability.
  • Scenario Outline values can become unrealistic placeholders if you don't provide a domain example.

Tips

  • Always include any acceptance criteria you have: the model generates much sharper edge cases when criteria spell out limits.
  • If output has a 'Scenario Outline' with only one Example row, refactor it to a regular Scenario.
  • Add the tag @smoke to the happy path scenario manually after generation: model rarely tags consistently.
  • Run scenarios past a non-engineer stakeholder. If they can't understand them, the BDD is failing its main job.

FAQ

When should I use Scenario Outline vs separate Scenarios?

Use Outline when the same flow (Given/When/Then) is exercised with 2+ data variations. Use separate Scenarios when the flow is fundamentally different: e.g., a happy path and an expired-link path have different Given/Then, not just different data.

How many scenarios per story?

Typically 4-6. If you have more than 8, the story is probably too big and should be split. If you have only 1-2, you're missing edge cases.

Can Gherkin handle API tests?

Yes. Write Given/When/Then in domain language ('Given I have an order with status pending', not 'Given the database has...'). Step definitions hit the API. Gherkin works equally well at the UI and API layer.

What's the biggest Gherkin anti-pattern?

Writing scenarios as scripts of UI clicks ('Then I click the button, then I see the modal, then I click OK'). That's not BDD: that's a recorded macro in disguise. Then steps should describe outcomes, not UI choreography.

Use with these tools