-
Notifications
You must be signed in to change notification settings - Fork 2
Concepts
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 |
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 doneWrite:
Scenario:
Given that something was done
And that something else was done
And that something more was doneThis reads more naturally and matches Gherkin best practices.
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:
-
Given — Context sentences (
that the context contains the key … with the value …) -
Then — Context sentences (
I store the string of the field … in the context …) - Predefined values in
application.yml(see Configuration)
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}"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 classpathAbsolute 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.
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>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}"