Add requests to URL-based load tests in Azure Load Testing
In this article, you learn how to add HTTP requests to a URL-based load test in Azure Load Testing. Use a URL-based load test to validate HTTP endpoints, such as web applications or REST endpoints, without prior knowledge of load testing tools and scripting.
Azure supports two ways to define HTTP requests in a URL-based load test. You can combine both methods within a load test.
- Specify the HTTP endpoint details, such as the endpoint URL, HTTP method, headers, query parameters, or the request body.
- Enter a cURL command for the HTTP request.
If you have dependent requests, you can extract response values from one request and pass them as input to a subsequent request. For example, you might first retrieve the customer details, and extract the customer ID to retrieve the customer order details.
If you use a URL-based load test in your CI/CD workflow, you can pass a JSON file that contains the HTTP requests to your load test.
You can add up to five requests to a URL-based load test. For more complex load tests, you can create a load test by uploading a JMeter test script. For example, when you have more than five requests, if you use non-HTTP protocols, or if you need to use JMeter plugins.
Prerequisites
- An Azure account with an active subscription. If you don't have an Azure subscription, create a free account before you begin.
- An Azure load testing resource. To create a load testing resource, see Create and run a load test.
Add requests with HTTP details
You can specify an HTTP request for a URL-based load test by providing the HTTP request details. The following table lists the fields you can configure for an HTTP request in Azure Load Testing:
Field | Details |
---|---|
URL | The HTTP endpoint URL. For example, https://www.contoso.com/products . |
Method | The HTTP method. Azure Load Testing supports GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS. |
Query parameters | (Optional) Enter query string parameters to append to the URL. |
HTTP headers | (Optional) Enter HTTP headers to include in the HTTP request. You can add up to 20 headers for a request. |
Request body | (Optional) Depending on the HTTP method, you can specify the HTTP body content. Azure Load Testing supports the following formats: raw data, JSON view, JavaScript, HTML, and XML. |
Follow these steps to add an HTTP request to a URL-based load test:
In the Azure portal, go to your load testing resource.
In the left navigation, select Tests to view all tests.
In the list, select your load test, and then select Edit.
Make sure to select a URL-based load test from the list and that you enabled Enable advanced settings on the Basics tab.
Go to the Test plan tab, and select Add request.
Select Add input in UI to enter the HTTP request details.
Enter the HTTP request details, and then select Add to add the request to your load test.
Field Description Request format Select Add input in UI to configure the request details through fields in the Azure portal. Request name Enter a unique name for the request. You can refer to this request name when you define test fail criteria. URL The URL of the application endpoint. Method Select an HTTP method from the list. Azure Load Testing supports GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS. Query parameters (Optional) Enter query string parameters to append to the URL. Headers (Optional) Enter HTTP headers to include in the HTTP request. Body (Optional) Depending on the HTTP method, you can also specify the HTTP body content. Azure Load Testing supports the following formats: raw data, JSON view, JavaScript, HTML, and XML. Select Apply to save the load test.
Add requests using cURL
Instead of providing the HTTP request details, you can also provide cURL commands for the HTTP requests in your URL-based load test. cURL is a command-line tool and library for URL-based requests.
Follow these steps to add an HTTP request to a load test by using a cURL command.
In the list of tests, select your load test, and then select Edit.
Make sure to select a URL-based load test from the list and that you enabled Enable advanced settings on the Basics tab.
Go to the Test plan tab, and select Add request.
Select Add cURL command to create an HTTP request by using cURL.
Enter the cURL command in the cURL command field, and then select Add to add the request to your load test.
The following example uses cURL to perform an HTTP GET request, specifying an HTTP header:
curl --request GET 'http://www.contoso.com/customers?version=1' --header 'api-token: my-token'
Select Apply to save the load test.
Use variables in HTTP requests
You can use variables in your HTTP request to make your tests more flexible, or to avoid including secrets in your test plan. For example, you could use an environment variable with the domain name of your endpoint and then use variable name in the individual HTTP requests. The use of variables makes your test plan more flexible and maintainable.
With URL-based load tests in Azure Load Testing, you can use variables to refer to the following information:
- Environment variables: you can configure environment variables for the load test
- Secrets: configure Azure Key Vault secrets in your load test
- Values from a CSV input file: use variables for the columns in a CSV input file and run a request for each row in the file
- Response variables: extract values from a previous HTTP request
The syntax for referring to a variable in a request is: ${variable-name}
.
The following screenshot shows how to refer to a token
variable in an HTTP header by using ${token}
.
Note
If you specify certificates, Azure Load Testing automatically passes the certificates in each HTTP request.
Use response variables for dependent requests
To create HTTP requests that depent on a previous request, you can use response variables. For example, in the first request you might retrieve a list of items from an API, extract the ID from the first result, and then make a subsequent and pass this ID as a query string parameter.
Azure Load Testing supports the following options to extract values from an HTTP request and store them in a variable:
- JSONPath
- XPath
- Regular expression
For example, the following example shows how to use an XPathExtractor to store the body of a request in the token
response variable. You can then use ${token}
in other HTTP requests to refer to this value.
"responseVariables": [
{
"extractorType": "XPathExtractor",
"expression": "/note/body",
"variableName": "token"
}
]