Gherkin and Feature Files
Learn how TestVibe uses Gherkin feature files to describe user behavior before generating Playwright tests.
Gherkin is a structured way to describe product behavior in plain language. TestVibe uses Gherkin-style feature files so test intent stays readable before it becomes generated Playwright code.
A good Gherkin feature explains what a user is trying to do, what actions they take, and what outcome proves the product worked.
New to the language? See the official Gherkin reference on cucumber.io for the full keyword specification.
Why Gherkin Matters In TestVibe
Gherkin gives TestVibe a clear source of truth for generation:
Product and QA users can read and edit the expected behavior.
AI generation has a structured description to turn into Playwright code.
Developers can review the behavior being tested before inspecting implementation details.
The Test Suite can organize tests by feature area, scenario, and generated status.
In a project, feature files usually live under Features/, often grouped by product area.
The Basic Shape
A Gherkin feature file usually contains a Feature, optional shared setup in Background, and one or more Scenario blocks.
Feature: Checkout
Background:
Given the shopper is on the store homepage
Scenario: Complete checkout with a saved card
Given the shopper has an item in the cart
When the shopper completes checkout with a saved card
Then the order confirmation should be displayedCore Gherkin Terms
Feature
The product capability or user journey being described.
Scenario
One concrete example of behavior inside the feature.
Background
Shared setup that should apply before each scenario in the feature.
Given
The starting context or precondition.
When
The action the user or system takes.
Then
The expected outcome that proves the behavior worked.
And
A continuation of the previous Given, When, or Then.
But
A contrast or exception related to the previous step.
Scenario Outline
A reusable scenario pattern that runs with different example values.
Examples
The table of values used by a scenario outline.
Feature
Use Feature to name the product behavior you want to cover.
Good feature names are user-facing and specific:
Feature: Password resetFeature: Timesheet approvalFeature: Checkout with saved payment method
Avoid feature names that are too broad, such as Feature: Website or Feature: Testing.
Scenario
Use Scenario for one concrete behavior. A scenario should usually describe a single successful path, failure path, or important variation.
If a scenario starts covering several unrelated behaviors, split it into smaller scenarios.
Given, When, Then
The Given, When, Then pattern helps separate setup, action, and expected result.
Given
Context that is already true before the main action.
Given the user is on the sign-in page
When
The important action being tested.
When the user submits valid credentials
Then
The result that should be verified.
Then the dashboard should open
The Then step is especially important for AI generation. If the expected result is vague, the generated test may only perform actions without proving the behavior worked.
Background
Use Background for setup that belongs to every scenario in the feature.
Keep backgrounds short. If the setup is long or only applies to one scenario, put it inside that scenario instead.
Always Start At The Entrypoint
Every TestVibe feature must begin at the site's landing entrypoint — the page the project's configured URL opens fresh: the home page, or the login page for an app behind authentication. Put that in the Background (or the opening steps of a single-scenario feature), then navigate forward with explicit steps to whatever deeper page (Settings, a record detail, an admin screen) the scenario actually needs.
Name the entrypoint by its screen state (Given I am on the home page, Given I am on the "Login" page) — never assume an already-signed-in session, an existing cart, or any other starting state that skips how the app was reached. Never hardcode a URL, domain, or localhost in a step; TestVibe already points the test at the project's configured site, so name the screen instead of the address.
Uniqueness For Created Data
A step that creates something (a sign-up email, a new project or record name) needs a value that's unique on every run — a fixed literal collides with what the previous run already created. Embed the {{unique}} token inside the value:
{{unique}} expands to a fresh stamp at run time, and every occurrence within the same run resolves to the same value — so a later step can assert against or sign back in with the value an earlier step created. It takes no arguments and needs no variable definition; a value that only references existing data should stay a plain literal. Credentials and other sensitive values use {{var:NAME}} / {{secret:NAME}} tokens instead — see Add API keys and secrets.
Scenario Outlines And Examples
Use a Scenario Outline when the same behavior should be checked with different values.
Scenario outlines are useful for variations, but keep the examples meaningful. If each row needs a different workflow, separate scenarios may be easier to understand.
Good Gherkin For AI Generation
Gherkin works best in TestVibe when it gives the generator clear, testable intent.
Do:
start every feature at the site's landing entrypoint (see above), then navigate forward
write steps from the user's point of view
mention visible labels, buttons, fields, and expected messages
include the outcome that must be verified
keep each scenario focused on one behavior
use real test data when a specific record, date, or account matters
put shared setup in
Backgroundonly when every scenario needs itwrap a value that creates new data in
{{unique}}so repeat runs don't collide
Avoid:
vague steps such as
When the user does the thingassuming a starting state (already signed in, already on a deep page) instead of reaching it step by step
hidden expectations that are not written in a
Thenlong scenarios that cover many unrelated flows
implementation details that a user cannot observe
hardcoding a URL, domain, or
localhost— name the screen, not the addresschanging data without describing how the test should end in a repeatable state
Structure Hint
While you edit, the Gherkin editor can surface a Structure hint — an accent button next to the editor that appears when your draft could read more cleanly. Click it to open a short piece of structure advice: pulling shared setup into a Background, starting at the entrypoint, keeping each scenario self-contained, or using credential tokens instead of literal values.
When the advice comes with a concrete rewrite, an Apply button edits your draft in place so you can review it. It never saves for you — the change lands in the editor as an unsaved edit you can undo, and you still click Save when you're happy with it.
How Gherkin Becomes Playwright Code
In TestVibe, Gherkin is the readable intent. Playwright is the executable browser automation.
The typical flow is:
Create or edit a Gherkin feature in the Test Suite.
Review the feature, scenarios, and steps.
Start generation.
TestVibe uses the feature intent to generate Playwright code.
Run the generated test.
Use results and evidence to decide whether to edit the feature, regenerate, or fix the application.
Example: Before And After
Vague instruction:
Better Gherkin:
The better version tells TestVibe what page to start from, what action matters, and what visible evidence proves success.
Where To Go Next
Create and organize features
Generate from Gherkin
Run and improve
Last updated
Was this helpful?
