Support Center
There are three types of steps:
Here's how they are related to each other:
"Given" steps describe the preconditions of a successful API invocation. That is, they let you specify what a correct request to invoke an endpoint. You'll be using "Given steps to populate JSON fields or to add HTTP headers and all of the "Given steps run before a "When" step runs.
"When" steps are the main point of interaction within a test. This is the moment when a remote endpoint is invoked using the request previously created with the test's "Given steps.
"Then" and "And" work the same and they always follow a "When" step. There always needs to be a "Then" step in a test, optionally followed by one or more "And" steps. They check the response that the API returns, possibly extracting some of its data for use in later tests.
The idea is to make your tests read like sentences in English.
"Given that I have this, given that I have that, when I do this, then that happens and another thing happens too".
Note that "Then" and "And" are the same steps and you can use any of them as the "Then" step. For instance, both of the examples below work the same.
Given address "https://example.com"
When the URL is invoked
Then status is "200"
And header "Server" is not empty
Given address "https://example.com"
When the URL is invoked
Then header "Server" is not empty
And status is "200"
Typically, you check the HTTP status first using "Then" and this is followed by "And" tests but sometimes there's no need to check the HTTP status code in which case you can put any other "And" step as the "Then" one.
And header "{expected_header}" exists
And header "Content-Type" exists
And HTTP header "Content-Type" exists
Any value in any step, what you insert between quotation marks, can be data given directly in the test, or it can be a local variable created previously, a variable from config.ini or you can use environment variables.
Given address "https://example.com"
Given address "#server_address"
Given address "@server_address"
Given address "$Server_Address"
The remainder of this document is a list of patterns that apitest recognizes. Some of them are discussed in detail, with examples, whereas some are self-explanatory given that they are already in English.
If you want to add your own steps, check the advanced usage document.
Given header "Accept" "*/*"
Given header "X-My-Header" "MyValue"
Given header "X-API-Key" "Bearer F6jwCOe3bLO6FkqANMW7vHQtblwPZpVYCN4Rq6FPB7"
"{}"
, or it can be a JSON dict, e.g. "{"order_type":"new"}"
Given date format "CRM_Date_Format" "MM-DD-YY""
Given path "/order/created" in request is a random date "CRM_Date_Format"
Given path "/order/shipped" in request is now "CRM_Date_Format"
Given path "/order/state" in request is "new"
Given path "/order/customer/type" in request is "#customer_type"
Given path "/order/customer/segment" in request is "@default_customer_segment"
Given path "/order/customer/market" in request is "@Default_Customer_Market"
"#"
Then I store "/order/id" from response under "order_id"
Given path "/customer/order/last_id" in request is "#order_id"
null
object (None in Python)When the URL is invoked
Then path "/status/details" starts with any of "["err_", "invalid_", "rejected_"]"
Given address "http://apitest-demo.zato.io:8587"
Given URL path "/demo/rest"
When the URL is invoked
Then status is "200"
Given header "{header}" "{value}"
explained aboveGiven OAuth2 endpoint "@my_endpoint"
Given OAuth2 credentials "@my_token_username" "$My_Token_Password"
Given I store an OAuth2 form bearer token under "my_token"
Given address "https://example.com"
Given URL path "/api"
Given REST method "GET"
Given OAuth2 bearer token "#my_token"
When the URL is invoked
Then status is "200"
--verbose
flag, e.g. "apitest run /path/to/tests --verbose"