...
Notice how special characters like line returns and quotes are escaped using ‘\'. If the content contains ‘\’ prior to being escaped, the ‘\’ is escaped by doubling up the '\’ to “\\”. Also, notice that the Content-Type header has to be explicitly added to the header section of this request (or could be added to the top-level header property that is inherited by all steps. Another consideration when deciding to use the short vs long form is the use of properties and variable placeholders. If the placeholder is contained in a quoted property name or value, the short form can be used without issue. However, if the placeholder is expected to be replace with structured content and the use of the placeholder is not quoted, the script definition will no longer be valid Json.
Info |
---|
You do not need to provide the Content-Length header with your request body. The system will automatically calculate the length of the body after any property or variable replacements and add the header for you. |
Making Multiple Requests
A test case may require making multiple requests. The top level “steps” property of the test definition is an array that can contain any number of test steps that will be executed in the order they appear when the test is run. Let’s combine our previous test definitions together:
...
Code Block | ||
---|---|---|
| ||
{ "headers": [], "steps": [ { "name": "Hello World", "type": "Request", "method": "GET" "url": "{{ServerDomain}}/hello", "body": null, "actions": [ { "name": "Capture Result", "type": "json", "extractionPairs": [ { "jsonPath": "text", "variableName": "myvar" } ] } ] }, { "name": "Echo", "type": "Request", "method": "POST" "url": "{{ServerDomain}}/echo", "headers": [], ["body": { "nametext": "Content-Type", My text content" }, "valueactions": "application/json" } ], "body": { "text": "My text content" }, "actions": [ ] } ] } |
All actions have these properties:
...
Code Block | ||
---|---|---|
| ||
{ "headers": [], "steps": [ { "name": "Hello World", "type": "Request", "method": "GET" "url": "{{ServerDomain}}/hello", "body": null, "actions": [ { "name": "Capture Result", "type": "json", "extractionPairs": [ { "jsonPath": "text", "variableName": "myvar" } ] } ] }, { "name": "Echo", "type": "Request", "method": "POST" "url": "{{ServerDomain}}/echo", "headers": [], { "name": "Content-Type", "value": "application/json" } ], ""body": { "text": "[[myvar]]" }, "actions": [ ] } ] } |
Info |
---|
Information about the differences between Properties and Variables can be found here |
Notice that the format of a variable reference is different from a property in that instead of surrounding the property name with “{{“ and “}}” you use “[[“ and “]]” for variables. When the session runs, it first makes the request to the hello world endpoint and then grabs the value from the “text” property of the response and stores it in the “myvar” variable. When the echo request is made, the placeholder reference “[[myvar]]” is replaced with the value stored in the “myvar” variable; “Hello World!” in our case.
Each time the session starts over, any variables captured during the previous run are removed to ensure nothing is carried over between loops. The only exception to this are variables captured or modified in the Initial and Maintenance scripts. Those variables are shared with all sessions and can only be modified by those scripts. If you attempt to update the value of a global variable within the Main script, and an error will be raised. Once a variable is populated, it is available to all later requests during the same loop even if the request is part of a different group.
Grouping Requests Together
Although the Main script provides the top-level “steps” array that can hold multiple steps, it’s sometimes beneficial to explicitly group steps together. You can provide a name for the group and the system will track metrics of the group as a whole in addition to the metrics from each request.
Sequence Group
The first type of group is a Step Sequence and acts exactly like the top-level “steps” array. The steps defined in the group are executed in the order they appear. Let’s move our existing requests into their own sequence:
Code Block | ||
---|---|---|
| ||
{
"headers": [],
"steps":
[
{
"name": "Hello and Echo",
"type": "Sequence",
"headers": [],
"steps":
[
{
"name": "Hello World",
"type": "Request",
"method": "GET"
"url": "{{ServerDomain}}/hello",
"body": null,
"actions":
[
{
"name": "Capture Result",
"type": "json",
"extractionPairs":
[
{
"jsonPath": "text",
"variableName": "myvar"
}
]
}
]
},
{
"name": "Echo",
"type": "Request",
"method": "POST"
"url": "{{ServerDomain}}/echo",
"headers": [],
"body":
{
"text": "[[myvar]]"
},
"actions":
[
]
}
]
}
]
} |
The structure of the sequence group is very similar to the top-level script except the addition of:
name - The name of the group
type - The type of the group (Sequence, Random)
The top-level script now has a single step; our sequence group. When the sequence group step is executed, its children are then executed in order before the sequence step is complete. If we were to add another Request to our top-level script after the the sequence, the sequence (and its two children) would be completed prior to making the third request. Being able to run a number of steps in order as a group can help organize the test. But what if you want to add some randomness to the test?
Random Group
Similar to the Sequence group, the Random group step allows you to define a set of child steps. However, instead of running each step in order each time the group is executed the Random group will pick one of the children at random and run that step. Once the selected step is executed, the Random group is complete and the test continues on to the next step at the same level as the Random Group. Let’s look at script that uses a Random group:
Code Block | ||
---|---|---|
| ||
{
"headers": [],
"steps":
[
{
"name": "Hello and Echo",
"type": "Sequence",
"headers": [],
"steps":
[
{
"name": "Hello World",
"type": "Request",
"method": "GET"
"url": "{{ServerDomain}}/hello",
"body": null,
"actions":
[
{
"name": "Capture Result",
"type": "json",
"extractionPairs":
[
{
"jsonPath": "text",
"variableName": "myvar"
}
]
}
]
},
{
"name": "Echo",
"type": "Request",
"method": "POST"
"url": "{{ServerDomain}}/echo",
"headers": [],
"body":
{
"text": "[[myvar]]"
},
"actions":
[
]
}
]
}
]
} |