What is HTTP?

HTTP stands for Hyper Text Transfer Protocol and it’s the underlying protocol used by the World Wide Web. This protocol defines how messages between client and server are transmitted and formatted, through HTTP Requests and HTTP Responses.
With Testerum, you’ll be able to send HTTP Requests and verify HTTP Responses from an intuitive UI, without having to write any line of code.

HTTP Request and Response over Web

How to execute an HTTP Request

  1. Create a new Feature
  2. First of all, lay the groundwork by creating a new feature and a new test. If you’re not familiar with this step, check out the getting started chapter. First Steps

  3. Step chooser
  4. After you click on the "+" button in the Steps section, a new window will pop up. Go to Basic Steps -> http -> request and select When I execute the HTTP request <<httpRequest>>.
    Http Request step chooser

  5. Define your test
  6. This step is about defining the HTTP call by writing the acceptance criteria. If you’re not familiar with how to write acceptance criteria, go here
    HTTP Request edit step

  7. Edit the HTTP Request
    • Edit HTTP methods/ URL/ Headers
    • Choose the HTTP method you want to use, add the URL and the headers.
      Http Request Edit Headers

    • HTTP Request Body
    • At this step, you just have to select the body format and the content type. After doing this, insert your HTTP request body and you’re ready to go!
      Tip: You have the option to make this HTTP request a Shared resource and use it every time you need.
      Http Request Edit Body

  8. Finalize your HTTP Request edit
  9. After you’re done editing, verify your request one more time and click Save.
    Http Request Finalized

  10. Test!
  11. Once you have correctly defined the steps, you’re ready to perform the test!
    After the test is done, check your results by clicking on the steps.

    Http Request execution

Data extraction

In this section you’ll learn how to extract data from a HTTP request and store it in variable. The example you’re seeing is an HTTP request for an authentication token, that will be used in another request.

HTTP Request function

If you execute the test above in Testerum, you’ll find the HTTP request and response in the console. Notice that they are written in JSON format.

Http Request Console

Recap: This example will show you how to extract the authentication token from an HTTP request, store it’s value in a variable and use it in other HTTP requests.
Start by adding a new step from the list. Go to Basic steps -> vars -> Given the variable <<name>> with value <<value>>

Http request variable step

In this example, we’ll replace the <<name>> with "AUTH_TOKEN" and inside the <<value>> we will use the expression {{httpResponse.jsonBody.authToken}}.
Basically, this newly created function will take the value of "authToken" from the HTTP response that we mentioned earlier. This value will be stored into the newly created variable "AUTH_TOKEN".
Other HTTP expressions are also possible.

Http request variales edit

At this point, the authorization token is stored in a variable.
The next step is to create a new HTTP request that needs the authorization token in the header. This HTTP request is sent to the server to create a new owner.
Tip: To use a variable, you have to put it inside curly brackets {{ }}

Http request create owner edit

Add the JSON to the Body.

Http request create owner Body

Check your work, save it and run the test. After the test is done, check the console and see the results.

Http request create owner execution

Other HTTP expressions

In the previous sections you learned how to extract parts of a JSON response by using an expression like {{httpResponse.jsonBody.authToken}}.
This section describes what other expressions are available.

After making an HTTP requests, two variables are created: httpResponse and httpRequest. In the following sections, we describe the models for these variables.

Response

protocol         : String,  // HTTP/1.1
statusCode       : int,     // 200
headers          : List<HttpResponseHeader>,
body             : byte[],  // body, exactly as received
bodyAsUtf8String : String,
jsonBody         : Map<String, String | int | boolean | null | Map}>  // httpResponse.jsonBody.person.name
getHeaderValue(key: String) : String   // returns the first header value for the provided key or null

HttpResponseHeader

key    : String,      // Content-Type
values : List<String> // we use a list to capture all values (HTTP allows a header to be specified multiple times)

Request

method          : HttpRequestMethod,
url             : String
headers         : Map<String, String>,
body            : HttpRequestBody | null,
followRedirects : boolean

HttpRequestMethod

enum {
    GET,
    POST,
    PUT,
    DELETE,
    HEAD,
    OPTIONS,
    TRACE,
    PATCH
}

HttpRequestBody

bodyType : HttpRequestBodyType
content  : String

HttpRequestBodyType

enum {
    RAW,
    FORM_DATA,
    X-WWW-FORM-URLENCODED,
    BINARY
}

HTTP Verify

You can verify the previously executed request, by using the step Then the HTTP response should be <<httpResponseVerify>>.

In view mode, it looks like this:
HTTP Verify in view mode

Click on the Edit button (the crayon icon) next to the parameter name to open the HTTP Response Verify.
HTTP Verify popup (edit mode)

The following can be verified:

  1. Status Code verification
  2. This allows you to specify what status code is expected.

  3. Headers verification
  4. This allows the verification of response headers.

    Multiple verification modes are available:
    HTTP Verify headers

  5. Body verification
  6. This allows you to verify the response body.

    Multiple verification modes are available:
    HTTP Verify body

    • JSON Verify: see the JSON verify section
    • Exact Match: the actual response body must be exactly the same as the expected body
    • Contains: the actual response body must contain the expected body
    • Match Regex: the actual response body must match the expected regular expression. See the documentation on the exact syntax of the regular expression.
    • Is Empty: the actual response body must not contain any characters, not even whitespace

JSON verify

Use this methods to verify if the JSON response is correct.

Simple verification

The simplest verification is to put in the expected body as-is:

Actual JSON
{
    "id": 3476,
    "firstName": "John",
    "lastName": "Doe"
}
Expected JSON
{
    "id": 3476,
    "firstName": "John",
    "lastName": "Doe"
}

Comparison functions

Instead of expecting a particular value, you can use comparison functions:

Actual JSON
{
    "id": 3476,
    "firstName": "John",
    "lastName": "Doe"
}
Expected JSON
{
    "id": "@isNotEmpty()",
    "firstName": "John",
    "lastName": "Doe"
}
In this case the actual JSON will match because 3476 satisfies the @isNotEmpty() function.

Available comparison functions:

If you want to compare against a text that begins with @, you will have to escape it:

"\\@alex says thanks".

Compare modes - Contains

The actual comparison is done according to a compare mode. The default compare mode is contains:

Actual JSON
{
    "id": 3476,
    "firstName": "John",
    "lastName": "Doe"
}
Expected JSON
{
    "firstName": "John",
    "lastName": "Doe"
}

Because the compare mode is contains, the actual JSON above will match the expected JSON, even though it has extra fields.

Compare modes - Exact

If you want the actual to have exactly the same fields as the expected, you need to use the exact compare mode:

Actual JSON
{
    "id": 3476,
    "firstName": "John",
    "lastName": "Doe"
}
Expected JSON
{
    "=compareMode": "exact"
    "firstName": "John",
    "lastName": "Doe"
}

This will not match, because the compare mode is exact, but the actual has an extra field (id).

Compare modes - Unordered exact

The compare mode unorderedExact is like exact, but ignores the order of items in an array:

Actual JSON
[2, 1, 3]
Expected JSON
["=compareMode: unorderedExact", 1, 2, 3]

This will match.

Compare modes per JSON node

The comparison can be done for the entire verification, as well as for each node in the JSON:

Actual JSON
[
    {
        "id": 14,
        "firstName": "Alex",
        "lastName": "Thompson"
    },
    {
        "id": 27,
        "firstName": "John",
        "lastName": "Doe"
    }
]
Expected JSON
["=compareMode: contains",
    {"=compareMode": "exact",
        "id": "@isNotEmpty()",
        "firstName": "John",
        "lastName" : "Doe",
    }
]

This will match. This example is a response from a GET/ persons API (get list of persons), used to check if a person was correctly created in that list (POST/ person). Notice that what we want is for the list to contain our person (regardless of other persons in the list), but the comparison on the item itself is done using the exact mode.

How different compare modes interact