Gherkin feature files


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 remarkablemark 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:

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

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

Here’s the Google search with Feature and Scenario:

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.



Please support this site and join our Discord!