This step builds the request body from a two-column Gherkin table where each row maps a field name to its value. String values that look like numbers are converted to JavaScript numbers, and the strings true and false are converted to booleans, so the resulting object reflects the correct types. Placeholder tokens in any value are expanded before type conversion. The entire body object is replaced by each call to this step.
Use this form when the payload has several fields and a table layout improves readability compared to a single-line JSON string. For a compact single-line payload, prefer the JSON-string body step. Both the I and we subjects are accepted.
Accepted phrasings
Given I set the request body with:
| field | value |
Given we set the request body with:
| field | value |
Examples
Given I set the request body with:
| name | Alice |
| email | alice@example.org |
| age | 30 |
Given we set the request body with:
| title | Hello World |
| body | First post |
| userId | 1 |
Given I set the request body with:
| status | published |
| priority | 5 |
| featured | false |
In a real scenario
Scenario: Submit a new post via the API using a table body
Given the API base URL is "https://api.example.org/v1"
And I set the header "Content-Type" to "application/json"
And I am authenticating as "editor" with "ed!t0r" password
And I set the request body with:
| title | Quarterly report |
| category | news |
| active | true |
When I send a POST request to "/articles"
Then the API response code should be 201
And the API response should contain "Quarterly report"