Writing Gherkin

Author clear Gherkin feature files for Restlyn, covering scenario structure, tables, and reusable steps.

Restlyn uses Gherkin .feature files as the source of truth for generating API tests.


✏️ Gherkin Syntax Basics

Feature: Title of the feature

  Scenario: Title of the test case
    Given base URL is "https://api.example.com"
    When I POST "/login" with:
      | email    | test@example.com |
      | password | secret           |
    Then response status should be 200
    And response body should contain key "token"

🧱 Supported Steps

✅ Base URL

Given base URL is "https://example.com"

✅ Request with body

When I POST "/login" with:
  | email    | test@example.com |
  | password | secret           |

✅ Status Assertion

Then response status should be 200

✅ Contains Assertion

And response body should contain key "token"

✅ Schema Validation

And response should match schema "userSchema"

♻️ Reusable Steps

Define reusable steps in stepLibrary.js like:

module.exports = {
  'I am logged in': {
    steps: [
      { method: 'POST', endpoint: '/login', body: { email: 'test@example.com', password: 'secret' }, extract: ['token'] }
    ]
  }
}

Then reference in feature:

When I am logged in

Migrated from the Restlyn documentation, with reviewed example and configuration corrections. Original Restlyn documentation.