Given I am authenticating as "username" with "pa$$word" password

This step adds an HTTP Basic Authentication header to the next API request. It accepts a username and a password, base64-encodes them in the format username:password, and sets the Authorization header to the resulting Basic <encoded> value. Any previous Authorization header is replaced before the new one is written.

All API state, including the authorization header, is reset automatically before each scenario, so credentials set in one scenario never leak into another. Use this step together with a base URL step and a request-sending step. If you need a Bearer token or a custom authorization scheme instead of Basic Auth, use the header-setting steps directly.

Accepted phrasings

Given I am authenticating as "username" with "password" password
Given we are authenticating as "username" with "password" password

Examples

Given I am authenticating as "admin" with "password123" password
Given we are authenticating as "user@example.org" with "secret" password
Given I am authenticating as "api-user" with "pass!word" password
Given we are authenticating as "reader" with "readonly" password

In a real scenario

Scenario: Authenticated user can retrieve their own profile
  Given the API base URL is "https://api.example.org/v1"
  And I am authenticating as "alice" with "s3cure!" password
  When I send a GET request to "/me"
  Then the API response code should be 200
  And the API response should contain "alice"

Related steps

Back to Api Steps