Given I set placeholder "{{placeholder}}" to "value"

This step registers a named placeholder and its replacement value. Placeholders are substituted throughout the scenario wherever they appear: in endpoint paths, request body strings, and header values. The placeholder name is used verbatim as a literal string match, so the convention of wrapping names in double braces, for example {{userId}}, is recommended to avoid accidental matches.

Placeholders are reset before each scenario, so values defined in one scenario never affect another. This step is particularly useful when a scenario needs to parametrize a URL segment or inject a dynamic token that was hardcoded for the test run. Both the I and we subjects are accepted.

Accepted phrasings

Given I set placeholder "{{name}}" to "value"
Given we set placeholder "{{name}}" to "value"

Examples

Given I set placeholder "{{userId}}" to "123"
Given we set placeholder "{{token}}" to "abcd-1234"
Given I set placeholder "{{postId}}" to "42"
Given I set placeholder "{{version}}" to "v2"

In a real scenario

Scenario: Fetch a specific user record by ID using a placeholder
  Given the API base URL is "https://api.example.org"
  And I set placeholder "{{userId}}" to "99"
  And I set header "Accept" with value "application/json"
  When I send a GET request to "/users/{{userId}}"
  Then the API response code should be 200
  And the API response should contain "99"

Related steps

Back to Api Steps