Given I set the following headers:

This step sets multiple HTTP request headers in one go using a two-column Gherkin table. Each row provides a header name in the first column and its value in the second. Placeholder tokens in any value are expanded before the header is stored. Setting the same header name in the table twice will result in the last row winning, as each row is processed in order.

This step is the preferred choice when a scenario requires three or more headers, keeping the feature file compact. It applies the same header map that single-header steps use, so headers set here are combined with any headers already registered in earlier steps. Both the I and we subjects are accepted.

Accepted phrasings

Given I set the following headers:
  | Header-Name | value |
Given we set the following headers:
  | Header-Name | value |

Examples

Given I set the following headers:
  | Content-Type  | application/json |
  | Authorization | Bearer token123  |
  | Accept        | application/json |

Given we set the following headers:
  | Content-Type    | application/json |
  | X-Api-Key       | abcd-1234        |
  | Accept-Language | en-US            |

Given I set the following headers:
  | User-Agent    | test-runner |
  | Cache-Control | no-cache    |

Given we set the following headers:
  | Authorization | Bearer {{token}} |
  | X-Request-ID  | req-001          |

In a real scenario

Scenario: Send an authenticated POST request with custom headers
  Given the API base URL is "https://api.example.org/v1"
  And I set placeholder "{{token}}" to "test-bearer-xyz"
  And I set the following headers:
    | Authorization | Bearer {{token}}  |
    | Content-Type  | application/json  |
    | Accept        | application/json  |
  When I send a GET request to "/orders"
  Then the API response code should be 200

Related steps

Back to Api Steps