Sometimes it is not possible to determine in advance how many times a loop should be repeated. Here is an example:
A user queries a Check Status page multiple times until the server completes a slow asynchronous transaction and redirects to a Result page. When recording such test case, it is unknown how many times during the load test each virtual user should query the Check Status page. To configure such scenario, it is necessary to use a Do...While (Conditional Loop). Conditional loops have a condition which is checked at the end of the loop to determine if the loop should continue or exit. You can configure a loop to exit when the condition returns true or false.
Two types of conditions are supported.
To make the provided example work, a Text Based exit condition should be defined. This condition has to verify if the response contains "Location:
To create a conditional loop, follow these steps:
1. Go to the Build Test Case node.
2. Select the starting object.
3. Right mouse click to open the context menu and Click Create Container -> Create Do...While.
4. A new object dialog will appear.
5. Select the last object in the loop
6. Click Create Do...While.
7. Set the Number of Repeats (Max) property to the maximum allowed number of loop iterations to avoid endless loops.
8. Optionally specify in the Delay before next Loop.
9. Select condition type as Text Based or Extractor Based
10. The Text Based condition is based on finding a specified text or regular expressions in an HTTP response . For this condition, type specify the following:
a. From the drop-down select Response to Search, where the specified text or regular expressions will be searched.
b. In the Search Text property, specify a character string that will be searched in the HTTP response.
c. In the Search Text Type property select Text if the search string is a text, or select Regular Expression if the search string is regular expressions.
d. In the Exit While Loop if Match? property select Yes to repeat the loop, when the search text is not found, and exit the loop, when the search text is found. Or select No to repeat the loop, when the search text is found and exit the loop when the search text is not found.
11.The Extractor Based condition is based on evaluating an extractor. For this condition type specify the following:
a. From the drop-down, select the Extractor Name that will be used
b. In the Text to compare property, specify a text to compare with the Extractor
c. In the Exit While Loop if Match ? property, select Yes to repeat the loop,when the extractor value is not found, and exit the loop when the extractor value is found. Or select No to repeat the loop when the extractor value is found, and exit the loop when the extractor value is not found.
Another way to create a loop is to select multiple objects the test case tree -> right click -> select Create Do...While. This will create a Do...While around the selected objects.
- No labels