- steps
- ~anonymous()
- ~basicAuth()
- ~basicAuthUsingFileCredentials()
- ~obtainAccessToken()
- ~obtainAccessTokenUsingFileCredentials()
- ~defaultContentType()
- ~setVariables()
- ~makeRequest()
- ~makeGraphQLRequest()
- ~addQueryString()
- ~addRequestBody()
- ~addRequestBodyWithContentType()
- ~addRequestBodyFromExample()
- ~addRequestBodyFromFile()
- ~setRequestHeaders()
- ~setRequestCookies()
- ~populatePlaceholder()
- ~receiveRequestWithStatus()
- ~receiveWithinTime()
- ~receiveText()
- ~responseHeaderEquals()
- ~responseBodyJsonPathEquals()
- ~responseBodyJsonPathMatches()
- ~responseBodyJsonPathIsEmpty()
- ~responseCookieEquals()
- ~validateAgainstSpecSchema()
- ~validateAgainstInlineSchema()
- ~validateAgainstFileSchema()
- ~printRequest()
- ~printResponseBody()
Explicitly state that the client is not authenticated (doesn't actually do anything).
Example
Given I am anonymous
Sets a base 64 encoded basic authentication header that is used on subsequent requests.
Example
Given I am using basic authentication with the credentials:
| username | <username> |
| password | <password> |
Example (Short form)
Given basic auth using:
| username | <username> |
| password | <password> |
Sets a base 64 encoded basic authentication header that is used on subsequent requests using credentials obtained from a Postman-like environment file.
Example
Given I am using basic authentication using credentials from: "/path/to/user.json"
Example (Short form)
Given basic auth using credentials from: "/path/to/user.json"
Supports logging into using OAuth2 credentials, typically with the password scheme. Sessions (access tokens) will be stored and supported for subsequent requests.
Example
Given I obtain an access token from "{base}/auth/token" using the credentials:
| client_id | harver |
| client_secret | harver123 |
| username | gerald |
| password | foobar |
| grant_type | password |
Example (Short form)
Given get token from "{base}/auth/token" using:
Supports logging into using OAuth2 credentials, typically with the password scheme Sessions (access tokens) will be stored and supported for subsequent requests
Example
Given I obtain an access token from "{base}/auth/token" using the credentials from: "/path/to/user.json"
Example (Short form)
Given get token from "{base}/auth/token" using credentials from: "/path/to/user.json"
Set a default Content-Type header for future requests. This is useful as a step in a feature's "Background"
Example
Given I am using the default content type: "application/json"
Example (Short form)
Given default content type: "application/json"
Set variable key/value pairs which will be automatically be substitued before sending requests.
Example
Given I set the variables:
| base | https://petstore.com |
| name | Fido |
Construct a request to a resource using an HTTP method Note: this should be the first "When"
Example
When I send a "GET" request to "/pets"
When I send a "POST" request to "/pets"
When I send a "PUT" request to "/pets/1234"
When I send a "DELETE" request to "/pets/1234"
Example (Short form)
When GET "/pets"
When POST "/pets"
When PUT "/pets/1234"
When DELETE "/pets/1234"
Construct a GraphQL query
Example
When I send the GraphQL query:
"""
{
pets {
id
name
type
}
}
"""
Example (Short form)
When GraphQL:
"""
{
pets {
id
name
type
}
}
"""
Add query string paramaters defined in a Gherkin data table
Example
When I add the query string parameters:
| sort | desc |
| filter | red |
Example (Short form)
When qs:
| sort | desc |
| filter | red |
Add a JSON request body included in the Gherkin doc strings
Example
When I add the request body:
"""
{ "name" : "Ka", "type" : "Snake" }
"""
Example (Short form)
When send:
"""
{ "name" : "Ka", "type" : "Snake" }
"""
Add a request body included in the Gherkin doc strings or data table with a given content type
The type "application/x-www-form-urlencoded" can be abbreviated to just "form".
Example
When I add the "form" request body
| name | Ka |
| type | Snake |
Example (Short form)
When send "form":
| name | Ka |
| type | Snake |
Adds a request body extracted from the open api spec for this request's resource and method. See the test openapi.yaml for an example.
Example
When I add the example request body
Example (Short form)
When send example body
Add a request body loaded from a file.
Example
When I add the request body from the file: "/test/files/json/sample-json"
Example (Short form)
When send from file "/test/files/json/sample-json"
Set one or more request headers in a single step.
Example
When I set the request headers:
| Content-Type | application/json |
| Accept-Language | en |
Example (Short form)
When set:
| Content-Type | application/json |
| Accept-Language | en |
Sets one or more cookies on the request using a data table.
Example
When I set the cookies:
| Name | Value | Flags |
| foo | bar | path=/ |
Example (Short form)
When set cookies:
| Name | Value | Flags |
| foo | bar | path=/ |
Say, in a previous scenario, a 'GET' request was sent '/pets'. We can extract data from this response and use it to populate placeholders in subsequent requests.
The example below will extract an id from a previously retrieved set of pets and use it to populate the placeholder to get a specific pet resource:
Example
When I send a 'GET' request to '/pets/{id}'
And I set the placeholder 'id' using the json path '$.[0].id' from the last 'GET' to '/pets'
Ensure the response was received with a given status. This should always be the first "Then" assertion.
Normally, HTTP redirects will be handled opaquely; the redirect is followed and the resulting response is asserted. However, if the status code to be asserted is a redirect status code the redirect will not be followed.
To assert the associated Location header use the appropriate separate step
Example
Then I should receive a response with the status 200
Example (Short form)
Then receive status 200
Ensure the response was received within a time limit. For slow netork connections use the LATENCY_BUFFER environment variable to increas this uniformly for all scenarios.
Example
Then I should receive a response within 500ms
Example (Short form)
Then within 500ms
Example
Then I should receive the text:
"""
The quick brown fox
"""
Example (Short form)
Then receive text:
"""
The quick brown fox
"""
Ensure a response header equals the expect value
Example
Then the response header "Content-Type" should equal "application/json"
Ensure a JSON response body equals a given value at the JSON path. Equality is determined
using ==
so giving value "10" will equal the number 10 in JSON.
See http://goessner.net/articles/JsonPath/
Example
Then the response body json path at "$.[1].name" should equal "Rover"
Example (Short form)
Then json path at "$.[1].name" should equal "Rover"
Ensure a JSON response body at the given JSON path, matches a regular expression. n.b. For simpliciy, Bat variables in regular expressions are not subsituted. See http://goessner.net/articles/JsonPath/
Example
Then the response body json path at "$.[1].age" should match "\d+"
Example (Short form)
Then json path at "$.[1].age" should match "\d+"
Ensure the JSON path is empty. See http://goessner.net/articles/JsonPath/ See https://www.chaijs.com/api/bdd/#method_empty
Example
Then the response body json path at "$.[1].name" should be empty
Example (Short form)
Then json path at "$.[1].name" should be empty
Asserts that a response sent a cookie to the client
Example
Then I should receive a response that sets the cookie
| Name | Value |
| foo | bar |
Example (Short form)
Then response sets cookie
| Name | Value |
| foo | bar |
This will extract the response body json schemea from the Open API spec and validate the current response body against it
Example
Then the response body should validate against its response schema
Example (Short form)
Then validate against schema
This allows you to provide an inline response schema to validate the current response body against. Generally not recommend because this can make the feature file very verbose.
Example
Then the response body should validate against the response schema:
"""
{ ... }
"""
Example (Short form)
Then validate against the schema:
"""
{ ... }
"""
This will load a response body json schemea from a file
Example
Then the response body should validate against the schema from "./path/to/schema.json"
Example (Short form)
Then validate against the schema from "./path/to/schema.json"
Debug step which prints the request that SuperAgent will send
Example
Then print the request
Debug step that will print the received response body.
This must run after the Then I should receive a response with the status <status>
step
but will not run if that step fails to assert. So you might need to temporarily change
this expectation in order to debug the response body received.
Example
Then print the response body