In a previous post I showed how to create a custom loop that permits you to create a loop in a web performance test to iterate from the char â€˜aâ€™ to char â€˜zâ€™, now I want to be able to create an inner loop that
- for each loop extract all the names of the customers that satisfy the search
- for each name ask for detail
I need another custom loop that is able to extract strings from the body of a response and iterate for each string. Here is the full code.
Listing 1: The full code of the RegexLoop plugin class
This plug-in has two property, the first Regex is used to define the regex to use, the other one is the name of Contextparameter used to store the result of the regex. This plugin simply iterates to each match of the regex, and permits you to create a loop based on text of the last request. This plugin is really simple, during initialization I execute the regex against the last response to grab a MatchCollection
Listing 2: The initialization function
Thanks to the e.WebTest.LastReponse.BodyString Iâ€™m able to access the body of the last response and execute the regex against it. The main loop is now straightforward to write
Listing 3: The main loop, iterate for each match
Now I can modify the test presented in the old post to insert an inner loop that is able to interate to all customers that satisfy the filter for each request.
Figure 1: Insert a loop based on a regular expression thanks to RegexLoop plugin
I inserted another loop inside the first one, after the search request, and insert a regular expression that is able to find all â€œselectâ€ button of the gridview, I asked the regexloop to insert the value in the CurrentCustomer context variable to use in the subsequent request
Fgirue 2: Use the CurrentCustomer context variable in the inner loop request
Now you can execute the test and verify the outcome, Iâ€™m expecting an external loop to search for all alphabet letters, then for each response an inner loop for each customer, as visible in Figure 3.
Figure 3: The result of the test, you can verify that all loops behave correctly.
Thanks to few lines of code now Iâ€™m able to execute loops based on content of a web response, that can be used to create complex web performance test in Visual Studio 2010.