Guide
User stories in Gherkin: from story to scenarios, with examples
By Miftode Vasilica, maker of Gherkin Studio ·
A user story says who wants something and why: "As a customer, I want to save my cart, so that I can finish the order later." Gherkin does not replace that sentence. It keeps it as the description of a Feature, and adds scenarios underneath: concrete examples of what "done" looks like. Below: how the two fit together, four stories turned into Gherkin, the mistakes that make a story harder to read, and where each part lives in Jira.
The story card and the feature file
The "As a… I want… So that…" sentence was first used at Connextra, in the UK, in 2001. The Agile Alliance glossary calls it the role-feature-reason format. Dan North added the second half in 2007, in his article "What's in a Story?": a title, the narrative, and then acceptance criteria written as scenarios with Given, When and Then.
Gherkin has a place for every part of that card.
| On the story card | In Gherkin | What Cucumber does with it |
|---|---|---|
| Title | Feature: line |
Shown in reports |
| As a… I want… So that… | Free text under Feature: |
Ignored when running; kept for reports |
| Acceptance criteria, as rules | Rule: lines |
Group the scenarios |
| Examples of each rule | Scenario: or Example: with steps |
Each one runs as a test |
Put together:
@SHOP-41
Feature: Save the cart for later
As a returning customer
I want my cart to be kept when I leave the shop
So that I can finish the order on another day
Rule: A cart is kept for 30 days
Example: Coming back after 29 days
Given I left 2 items in my cart 29 days ago
When I open the shop
Then my cart holds the same 2 items
Example: Coming back after 31 days
Given I left 2 items in my cart 31 days ago
When I open the shop
Then my cart is empty
The three lines under Feature: are the story, word for word. Gherkin's reference says this description is free text: write anything you like, as long as no line starts with a keyword. The scenarios are what makes the story checkable.
The scenario belongs to the story, not to the screen
The narrative explains why. The scenarios explain how you will know it works. A common mistake is to fill the scenarios with the screen instead:
Scenario: Save cart
Given I am on the home page
When I click "Add to cart"
And I click the cart icon
And I close the browser
And I open the browser
And I go to the home page
Then I see 2 items in the cart icon
Seven steps, and the one fact the story is about, 30 days, is missing. Nobody in a refinement meeting can disagree with this scenario, so nobody learns anything from it. The two short examples above say more, and they still read the same when the shop gets a new design.
Four stories, turned into Gherkin
Each one shows the story first, then the rules the team found, then the examples at the edge of each rule.
A subscription. As a subscriber, I want to pause my plan, so that I do not pay during a holiday.
@SUB-8
Feature: Pause a subscription
As a subscriber
I want to pause my plan
So that I do not pay while I am away
Rule: A pause lasts between 1 and 3 months
Example: Pausing for 3 months
Given I have an active monthly plan
When I pause it for 3 months
Then I am not charged until 3 months from today
Example: Asking for 4 months
Given I have an active monthly plan
When I try to pause it for 4 months
Then I see "You can pause for up to 3 months"
Rule: A paused plan can be restarted at any time
Example: Coming back early
Given my plan has been paused for 2 weeks
When I restart it
Then I am charged today
And my next charge is one month from today
An approval. As a team lead, I want to approve expenses over $500, so that large costs are checked before they are paid.
@FIN-112
Feature: Approve large expenses
As a team lead
I want expenses over $500 to wait for my approval
So that large costs are checked before payment
Scenario: An expense under the limit is paid without approval
Given Ana submits an expense of $499
Then the expense is sent for payment
Scenario: An expense over the limit waits
Given Ana submits an expense of $501
Then the expense waits for approval from her team lead
And her team lead is notified
No When in either scenario. Submitting is the starting point, and the result follows from it. Gherkin does not require all three keywords.
A notification. As a project member, I want an email when someone mentions me, so that I do not miss a question.
@COL-19
Feature: Email on mention
As a project member
I want an email when someone mentions me
So that I do not miss a question
Scenario: Mentioned in a comment
When Bogdan mentions me in a comment on "Q3 plan"
Then I receive an email with the comment text
And the email links to the comment
Scenario: Mentioning myself
When I mention myself in a comment
Then I receive no email
The second scenario is the one that came out of the conversation. Nobody wrote "except yourself" on the card. Somebody asked.
A report. As an accountant, I want to export invoices for a month, so that I can send them to the tax office.
@ACC-5
Feature: Export monthly invoices
As an accountant
I want to export the invoices of one month
So that I can send them to the tax office
Scenario Outline: Which invoices are included
Given an invoice dated <date>
When I export the invoices for March 2026
Then the invoice <included> in the export
Examples:
| date | included |
| 1 March 2026 | is |
| 31 March 2026 | is |
| 1 April 2026 | is not |
A Scenario Outline runs once per row of the table. Here the rows are the edges of the month, which is where an export usually goes wrong. More in how Scenario Outline and Examples are read.
How to turn a story into scenarios
- Read the "so that" first. It tells you what must not break. In the cart story, it is "finish the order on another day".
- Ask for the rules. What limits, roles or dates apply? Each answer is a rule. Write it as one sentence.
- Ask for an example of each rule. Then ask for the one just past the limit: 29 and 31 days, $499 and $501.
- Write each example as Given, When, Then. Given is the situation before. When is the action. Then is what someone can see.
- Drop what does not matter. If the starting state is not important, leave out the Given. If a rule is obvious, it needs no example at all.
Steps 2 and 3 are usually done together, with a product person, a developer and a tester in the room. See three amigos and example mapping.
Mistakes that make a story harder to read
| Mistake | What happens | Instead |
|---|---|---|
The narrative is written as a step: Given I am a customer |
The role becomes a test step, and every scenario repeats it | Keep the role in the free text under Feature: |
| One feature file holds five stories | Nobody can tell which story a failing scenario belongs to | One story, one feature; tag it with the story key |
| The "so that" is left out | Nobody can say whether a scenario matters | Keep the reason, even when it feels obvious |
| A scenario for every click | Long scenarios that change with every redesign | Describe what the person does, not how. See how to write good Gherkin scenarios |
| Twelve scenarios for one story | The story is too big | Split it along its rules. Each rule can be its own story |
Where each part lives in Jira
- The title is the story's summary.
- The "As a… I want… So that…" sentence usually sits at the top of the description. That is fine: it is read by people, not run.
- The acceptance criteria are sentences. Teams keep them in the description or in a field of their own. See acceptance criteria in Given-When-Then format.
- The scenarios need a place that keeps Gherkin intact: indentation, tables and the
@SHOP-41tag that ties them to the story. A description loses those the first time someone edits it with the rich-text editor.
In Gherkin Studio, the scenarios sit in a panel on the story, also called Gherkin Studio. The editor colours the keywords and checks the syntax as you type. When your CI sends a Cucumber report, the result for that story appears on the story itself.
Short answers
Can I write a user story in Gherkin?
You can keep the story inside a Gherkin file, as the free text under Feature:. The story itself is still a sentence. Gherkin adds the examples.
What is the Gherkin format for a user story?
A Feature: line with the story title, the "As a… I want… So that…" lines under it, then one or more scenarios with Given, When and Then.
Is "As a… I want… So that…" required in a feature file?
No. The description is optional and Cucumber ignores it when running. Keep it if it helps readers.
How many scenarios does a user story need?
Enough to show each rule at its edge. Dan North suggests that a story with more than five or six scenarios is a candidate for splitting.
What is the difference between a user story and a scenario?
A story is a request: who wants what, and why. A scenario is one example of the behaviour that satisfies it, written so it can be checked.
Where Gherkin Studio fits
Gherkin Studio is a BDD app for Jira Cloud, built on Atlassian Forge. It is on the Atlassian Marketplace, with a 30-day free trial. See also BDD examples, from a Jira story to a passing test.