Skip to content

Concepts

Jörg Flade edited this page Jun 24, 2026 · 2 revisions

Concepts

Sentence conventions

The library defines a consistent prefix for each Gherkin step type to make IDE auto-complete useful:

Step Sentence starts with Purpose
Given that or I set Prepare something
When executing a Do something
Then I ensure or I store Validate something

Use And / But instead of repeating the keyword

Gherkin offers And and But as aliases for any step type. Every library sentence works with them.

Instead of:

Scenario:
  Given that something was done
  Given that something else was done
  Given that something more was done

Write:

Scenario:
  Given that something was done
  And that something else was done
  And that something more was done

This reads more naturally and matches Gherkin best practices.

ScenarioContext

ScenarioContext (also called ScenarioStateContext) is a key/value map that lives for the duration of one scenario. It is the primary mechanism for passing data between steps — for example, storing an ID from a POST response and using it in a subsequent GET.

Values are written to the context by:

Values are read from the context automatically anywhere a step accepts a {string} argument — if the string matches a key in the context, the stored value is substituted.

The same substitution works inside path templates using ${key} syntax:

When executing an authorized GET call to "/api/v1/users/${CREATED_USER_ID}"

File paths

Steps that reference files (request bodies, expected response JSON, SQL queries, CSV files) support two forms:

Relative to the base file path (recommended):

Background:
  Given that all file paths are relative to "features/users"

Scenario:
  Then I ensure that the body of the response is equal to the file "expected/user.json"
  # resolves to: features/users/expected/user.json on the test classpath

Absolute from the classpath root — prefix with absolutePath::

Then I ensure that the body of the response is equal to the file "absolutePath:shared/expected/user.json"

Set the base path in Background so it applies to all scenarios in the feature and only needs to change in one place.

URL base path

Similarly, a base URL path avoids repeating the common prefix on every When step:

Background:
  Given that all URLs are relative to "/api/v1/users"

Scenario:
  When executing an authorized GET call to "/${USER_ID}"
  # calls /api/v1/users/<value of USER_ID from context>

Context placeholders in strings

Any string argument — URL paths, body field values, header values — is checked against the context map first. If the argument exactly matches a context key, the stored value is used instead of the literal string.

For URL paths, use ${key} template syntax for inline substitution:

When executing an authorized GET call to "/api/v1/${TENANT_ID}/resources/${RESOURCE_ID}"

Clone this wiki locally