Knowledgebase

How to use LoadImpact request builder


Background

The LoadImpact request builder is fast and easy way to build tests in LoadImpact with minimal scripting. You simply input the endpoints, and required parameters and we will build the script for you. You can even specify Checks, correlate variables, and more.

In the words of our developer, Simon, who built it, “Go from zero to hero in load testing without breaking a sweat.”


In this guide we will go through the mechanics and parts of the LoadImpact request builder UI.

Basic usage

Creating a single endpoint test is dead simple, all that is required is basically the URL you want to test.
If the run test button is enabled it means that the configuration is valid and can be run. Hit run test and the test will start running with default load settings.

Would you want to change the load settings refer to configuring load settings.

The following example is a simple test that requests one endpoint and checks that the HTTP status code is 200. basic test basic test loading basic test starting

Configuring load settings

If you want to change the duration of the test and/or how many VUs are used, press the configure button and a config screen will appear. load test config In this screen you can change the duration of the test, how many VUs (virtual users or “traffic”) you want, the ramping profile (how traffic is increased and decreased during the test) and what load zones (geographical regions) the load should be generated from.

If you are not familiar with these concepts please refer to these articles:


Advanced usage

Creating a test with payloads, headers, authentication and asserts might sound difficult and tedious. The request builder UI makes it very straight forward.
In the following example we will authenticate, declare variables, set headers, send JSON data to create and update resources, delete resources and make checks to validate HTTP response codes and verify response data values.

Add a JSON payload to send with the request add payload

Set request headers set headers

Declare a variable userToken that can be used for authorized consecutive requests declare variable

Create checks to verify that:

  1. HTTP status code is 200
  2. The property token is present in the data returned from the server create checks

Add a new post request to create a resource create a new record

Use the previously declared variable in a request header variable in header

Check that the HTTP status code is 201 check status code

Declare a new variable crocodileId declare a new variable

Create a new PATCH request to update the resource we just created.
Notice that the variable crocodileId is being used as a part of the URL new patch request

Again, add the auth header auth header

Create a new GET request to get the information of the resource we just updated.
Notice that the variable crocodileId is being used as a part of the URL new get request

Add checks to verify that the data was actually updated verify data

Create a new DELETE request to delete the resource we created delete request

Check the status code to see that it is 204 status code check

This is what the final result looks like.
You can switch over to code mode and preview the Javascript generated from your config, you switch mode by clicking the </> symbol in the top right corner.

If you want to do even more advanced things you can create a test based on your configuration too! Check out the following Bailing out of the UI section for more information. final result

Hit run test to run with default load settings or configure to change settings like duration, VUs (virtual users), load ramping profile or geographical load zones. load config

Hit save and run and the test will start running.


Bailing out of the UI

The request builder UI is flexible and can be configured in many different ways. If you reach a point where you cannot configure the test in the way you want you can always drop down into JavaScript and modify the code directly.
Switch over to script preview mode and press the create test from script button to create a JavaScript test based on the current configuration. This will create a new test script based on the code in the request builder. Your request builder script will not be altered. You may find this helpful if you need to add more advanced business logic to your test. javascript


Request headers

Add information about the client or the resource being fetched. Set an Authorization header with access token to make authorized requests to your API. using headers


Query parameters

Query parameters can either be added in this panel or typed directly in the URL. query parameter


Variables

In some situations it is useful to utilize the data returned in one of the previous request, such as a token or other dynamic data, this is where variables come in handy.

Declaring variables

Variables require two things a name that can be referenced in consecutive requests and an expression to know what value to assign the variable.

There are two different expression types you can use when defining variables

JSONpath

Specifying the path to a property in the JSON data structure for which you want to assigning the variable. The JSONPath expression always starts with a $. followed by the path to the value.

Here is an example:

Data returned from server

1
2
3
4
5
6
{
  user: {
    name: "Batman",
    token: "xyz123"
  }
}

Corresponding JSONpath for name and token
json path example

For more information on JSONPath syntax refer to the repo here.

Regex

Specifying a regular expression. This can be useful if the data returned is not JSON but for example plain text.
If you are not familiar with regular expressions, here are some useful links for you:

Here is an example using regex:

Data returned from server

1
2
3
Hello this is a message of somekind
phone_number:000000000
sender:Bruce Wayne

Regex to extract the number regex example

Notice that there are “(..)” parentheses around [0-9]{10}, this is how you specify what part of the match (if any) you want to assign to the variable.
In the case of multiple matches the first match will assigned to the variable.

Using variables

Variables can be used in many different ways, here is a complete list of how you can use variables.

  • Headers - this is probably the most common use case, using a token to make authorized request to protected endpoints. using variable in headers

  • URL - using one of the declared variables as a part of the request URL.
    This can be useful if you want to perform actions on a specific resource. using variable in url

  • Query parameter - query parameters are a part of the URL making this very similar to the previous example.
    Using variables as query parameter can be accomplished in two ways, either add the query parameter directly in the URL input or in the query parameter panel. using variable in url

  • Request payload - using a variables value as a part of a request payload. variable request payload


Sending a payload

In some cases you might want to make a request to create or update a resource with some data.
First select a HTTP method that supports a request payload, then select what type of data you want to send. There are three different choices JSON, text and file content.

  • JSON - send a JSON data structure to your api. payload json

  • Plain text - send plain text payload. payload plain text

  • File content - upload a file and send a base64encoded payload. payload file content


Checks

Checks are like asserts, simple pass or fail conditions. They will not halt execution of your test. Checks are great for codifying assertions relating to HTTP requests/responses, making sure the response code is 2xx for example.

There are multiple types of checks you can add. These are the different types of checks available:

HTTP status code - this is more of a shorthand for the check type text. You can easily test that a status code is 2xx, 5xx and 4xx.. etc. check http status code

JSONPath value - check againt properties in a JSON data structure.
If you are not familiar with JSONPath take a look at the earlier section about JSONpath.

Here is an example where we are are checking the value of the users name and email.

1
2
3
4
5
6
7
// Data returned from server
{
  user: {
    name: "Batman",
    email: "batman@wayneenterprises.corp"
  }
}

Corresponding JSONPath expressions. jsonpath value expression

JSONPath assert - check for the existence of a specific property in a JSON data structure.
If you are not familiar with JSONPath take a look at the earlier section about JSONpath.

Here is an example where we are are checking that the data returned from the server contains the properties token and secret.

1
2
3
4
5
// Data returned from server
{
  token: "xyz123",
  secret: "supersecret"
}

Corresponding JSONPath expressions. jsonpath check

Text - this type of check is slightly different from the JSONPath alternatives in that you can select a subject to check against. The subjects available are response body, response headers and HTTP status code. text check

Regex - just like text this also lets you select a subject to check against.

In the following example we are checking that:

  1. response body contains a string timestamp: followed by a timestamp e.g 02-22-2019.
  2. HTTP status code is 2xx.
  3. there was a request header in the response with uid= followd by four digits e.g 1234.

regex check


Importing HAR file

To quickly populate the request builder UI you can import a HAR file. import har file


Tips and tricks

Change order of requests
Hover the request and a varr will appear, click and drag this symbol to change order of your requests
drag and drop

Remove and duplicate requests
Click the vellip symbol to reveal a menu with options to duplicate and remove the request
drag and drop


Troubleshooting

The configure and run test buttons are disabled!?
Whenever there is a conflicting configuration or someting is missing in order for the test to be run a red light will show up. Hover or click the red light and you will see the error that needs to be fixed in order for the test to be run.
validation error

Here is another example of a error message where we are trying to use a variable without it being declared.
validation error variable