What are Gherkin feature files?

Half cucumber on a white background
Photo by Mockup Graphics on Unsplash

Background

What are Gherkin feature files? They’re human-readable documentation that can map to automated tests.

Gherkin is a DSL (domain-specific language) for BDD (behavior-driven development).

Example

Here’s an example of using Gherkin to describe how to search for on Google:

Given I am on "https://www.google.com/"
When I click on the search bar
And I type "remarkablemark"
And I press "Enter"
Then I see in the search results "remarkablemark.org"

Each line is a step:

  • sets up the scenario.
  • describes the action.
  • states the expected outcome.
  • chains successive ’s, ’s, and ’s.

Steps can be organized under ’s, and they’re all under a single .

Here’s the Google search with and :

Feature: Google search
Scenario: Search for remarkablemark
Given I am on "https://www.google.com/"
When I click on the search bar
And I type "remarkablemark"
And I press "Enter"
Then I see in the search results "remarkablemark.org"

Resources

To learn more about the syntax, go to Gherkin Reference.

To see a feature file used as an automated test, check out the cucumber example in webdriverjs-recipes.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store