Guide
Cucumber feature file: a complete example, and how Cucumber runs it
By Miftode Vasilica, maker of Gherkin Studio ·
A Cucumber feature file is a plain-text file with the .feature extension. It describes one feature of your software as scenarios, written in Gherkin. Cucumber reads the file, matches each step to a piece of code called a step definition, and runs every scenario as a test. Below is a complete feature file, the step definitions that make it pass, where the files go in four popular tools, and how to run one scenario. We ran every example on this page with cucumber-js 13.3.
A complete feature file
The file is features/sign_in.feature:
@PROJ-7
Feature: Sign in
Customers sign in with their email address and password.
After five wrong passwords in a row, the account is locked for 15 minutes.
Background:
Given a customer "[email protected]" with the password "correct horse"
Scenario: Correct password
When I sign in as "[email protected]" with "correct horse"
Then I see my order history
Scenario Outline: Wrong password
Given I have already entered a wrong password <before> times
When I sign in as "[email protected]" with "wrong"
Then I see the message "<message>"
Examples:
| before | message |
| 0 | Email or password is incorrect |
| 4 | Too many attempts. Try again in 15 minutes |
Scenario: Devices I signed in from
Given I signed in from these devices:
| device | last used |
| Laptop | 2026-11-02 |
| Phone | 2026-11-18 |
When I open "Devices" in my account
Then I see 2 devices
| Part | What it does |
|---|---|
@PROJ-7 |
A tag on the whole feature. Every scenario inherits it. Here it is also the Jira issue the feature belongs to. |
Feature: and two lines of text |
The name, and a description for people. Cucumber does not run the description. |
Background: |
A step that runs before each scenario. |
Scenario: |
One example of the behaviour, as steps. |
Scenario Outline: with Examples: |
The same steps with different values. <before> and <message> come from the table, one run per row. |
| The table under "these devices" | A data table, handed to the step's code as one argument. |
Every keyword is explained in the Gherkin syntax guide.
What Cucumber does with it
Cucumber turns the file into four scenarios: the first one, the outline once for each of its two rows, and the devices one. The background step is added to the start of each.
Then it looks for a step definition for every step. On the first run there are none, and it says so:
4 scenarios (4 undefined)
15 steps (15 undefined)
It also prints a snippet for each missing step, ready to paste:
When('I sign in as {string} with {string}', function (string, string2) {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
{string} matches text in quotes. {int} matches a whole number. For a number, cucumber-js offers two snippets, one with {int} and one with {float}. Keep the one you need.
The step definitions that make it pass
This is sign_in.steps.js, in the features/step_definitions/ folder. It fakes the shop in memory, so it shows the matching and nothing else:
const { Given, When, Then } = require('@cucumber/cucumber');
const assert = require('node:assert');
Given('a customer {string} with the password {string}', function (email, password) {
this.accounts = { [email]: password };
this.failures = 0;
});
Given('I have already entered a wrong password {int} times', function (count) {
this.failures = count;
});
When('I sign in as {string} with {string}', function (email, password) {
if (this.accounts[email] === password) { this.page = 'Order history'; return; }
this.failures += 1;
this.message = this.failures >= 5 ? 'Too many attempts. Try again in 15 minutes' : 'Email or password is incorrect';
});
Then('I see my order history', function () {
assert.strictEqual(this.page, 'Order history');
});
Then('I see the message {string}', function (expected) {
assert.strictEqual(this.message, expected);
});
Given('I signed in from these devices:', function (table) {
this.devices = table.hashes();
});
When('I open {string} in my account', function (section) {
this.section = section;
});
Then('I see {int} devices', function (count) {
assert.strictEqual(this.devices.length, count);
});
The run now ends with:
4 scenarios (4 passed)
15 steps (15 passed)
We also changed the 4 in the examples table to 3 on purpose. One scenario failed, as it should: after three wrong passwords and one more, the account is not locked yet.
Two things worth knowing. this is a fresh object for every scenario, so values do not leak from one scenario to the next. And table.hashes() turns the data table into a list of rows, one object per row, keyed by the header.
Where feature files go
| Tool | Feature files | Step definitions |
|---|---|---|
| cucumber-js (JavaScript) | features/, any depth |
Also under features/. Both are found without any setting. |
| Cucumber-JVM (Java) | src/test/resources/<package>/ |
src/test/java/<package>/ |
| behave (Python) | features/ |
features/steps/, any .py file there |
| pytest-bdd (Python) | Next to the test module, or a base folder set in bdd_features_base_dir |
A test module that calls scenarios("sign_in.feature") |
The cucumber-js row is what we saw in our run. The other three come from each tool's own documentation.
Naming and organising
Cucumber does not care what the file is called, as long as it ends in .feature. People do. A few habits make a folder of feature files easy to find your way around:
- One feature per file. The parser insists on it anyway: a second
Feature:in the same file is an error. - Name the file after the feature, not after the sprint.
sign_in.feature,password_reset.feature. Lower case with underscores or hyphens, whichever your codebase already uses. - Group by area.
features/account/sign_in.feature,features/checkout/discounts.feature. - Split when it gets long. The Cucumber reference has a good test. Read a scenario: if the background has already scrolled off the screen, the file is doing too much.
If your feature files are tied to Jira issues, put the issue key in a tag (@PROJ-7), as above. Some teams also use it as the file name: PROJ-7.feature.
Comments in a feature file
Only a line that begins with # is a comment. Put one after a step, as in When I sign in # remember me, and it becomes part of the step text. Cucumber then looks for a step definition with # remember me in it, and finds none. More on comments and the rest of the syntax.
Running one file, one scenario or one tag
| To run | cucumber-js command | What it ran in our test |
|---|---|---|
| Everything | npx cucumber-js |
4 scenarios |
| One file | npx cucumber-js features/sign_in.feature |
4 scenarios |
| The scenario on one line | npx cucumber-js features/sign_in.feature:9 |
1 scenario |
| One row of an examples table | npx cucumber-js features/sign_in.feature:20 |
1 scenario |
| Everything with a tag | npx cucumber-js --tags "@PROJ-7" |
4 scenarios |
| Scenarios by name | npx cucumber-js --name "Wrong password" |
2 scenarios |
The line number can point at a scenario or at a single row of an Examples: table. A tag that matches nothing is not an error: the run ends with 0 scenarios. Check the count, so a typo in a tag does not pass for a green build.
Feature files and Jira
Feature files usually live in Git, next to the code. The stories they describe live in Jira. The link between the two is the issue key, in a tag or in the file name.
Gherkin Studio keeps the two sides together. Each story's scenarios are synced two-way with <folder>/KEY-123.feature in your GitHub, GitLab.com or Bitbucket Cloud repository. Read how two-way sync of .feature files works and the tag forms that link a scenario to an issue.
Short answers
Is a feature file the same as Gherkin?
Gherkin is the language. A feature file is a file written in it, with the .feature extension.
How many scenarios can one feature file have?
As many as describe that one feature. Split the file when the scenarios stop being about one thing.
Can one feature file have two features?
No. The parser stops at the second Feature: with an error.
What does "undefined" mean in the Cucumber output?
A step has no matching step definition yet. Cucumber prints a snippet you can paste and fill in.
Do I need Cucumber to use feature files?
No. behave and pytest-bdd read them too. And a feature file is readable on its own: product owners review them without running anything.
Where Gherkin Studio fits
Gherkin Studio is a BDD app for Jira Cloud, built on Atlassian Forge. You write the scenarios in the Jira story; they become a .feature file in your repository, and test results come back to the story. It is on the Atlassian Marketplace, with a 30-day free trial.