Walkthrough: Adding a Loop to a Web Performance Test

In this walkthrough, you will add a simple counting loop to a web performance test that will cause a web request in a web performance test to run through several iterations.

You can add loop logic to web performance tests that are configured with specific conditional rules and properties. This provides a simple way to have requests within a web performance test run multiple times. For more information, see Adding Loop and Branch Logic to Web Requests in Web Performance Tests.

In this walkthrough, you will perform the following tasks:

  • Add a counting loop to a web performance test

  • Run the web performance test to verify that it works correctly

Prerequisites

To complete this walkthrough, you need the following:

Considerations for Using Loops

Consider the following potential issues when using loops in a web performance test or a load tests using the web performance test:

  • When you run the web performance test on its own, that is, not in a load test, the entire web test result is kept in memory. Therefore, a web performance test that contains a loop with a lot of iterations can consume a lot of memory.

  • When you run this web performance test in a load test, if the test takes a long time to run it will have an impact on the test mix in the load test. The load test engine will treat running the web performance test as a single iteration. If, in fact, the web performance test is running many iterations, you will not get the desired mix.

In general, an iteration through the web performance test should be a model of what a single user will do on the site. It’s possible that some users might add several items to a shopping cart in a single session but that does not skew the model. However, looping should not be used to have a single user looping hundreds of times. Instead, let the load engine schedule that particular user hundreds of times. When possible, use less than 10 iterations in your loops.

Preparing for the Walkthrough

For this walkthrough, you will have to revert the changes that you made to the Local (local.testsettings) test settings that were made in the walkthrough Walkthrough: Adding Data Binding to a Web Performance Test (CSV File).

To Revert the Test Settings Changes

  1. On the Test menu point to Edit TestSettings, and then choose Local (local.testsettings).

  2. In the Configure Test Settings dialog box, select Web Test in the left pane, and then select the Fixed run count option in the right-side pane. Make sure that its value is set to 1.

  3. Choose Close.

  4. Choose Yes when you are prompted to save changes.

Add a Loop to the Web Performance Test

Add the Counting Loop

  1. In the Web Performance Test Editor, find the request that you changed in Walkthrough: Adding Data Binding to a Web Performance Test (CSV File) to bind to ColorsCSV. This should be the second node in the request list.

    Important

    The web application uses a redirect to move from the page Default.aspx to the page Red.aspx. In the web Performance Test Editor, the request list will show Default.aspx, not Red.aspx, for the request you are trying to find. To find the correct request, expand the request node, expand the Form Post Parameters folder, and confirm that there is an entry RadioButtonList={{ColorsCSV.ColorsCSV#csv.ColorName}}.

  2. In the Web Performance Test Editor, right-click the identified node and then choose Insert Loop.

    The Add Conditional Rule and Items to Loop dialog box appears.

  3. On the left side of the dialog box, in the Select a rule list, choose Counting Loop.

  4. On the right side of the dialog box, under Properties for selected rule, under the Options header change the value for Max Number of Iterations to 8.

  5. Under the Properties header, for the Context Parameter Name property type Loop Counter.

  6. Change the value for Number of Iterations to 8.

  7. Choose OK.

  8. In the Web Performance Test Editor, expand the Data Sources node, expand the ColorsCSV node, expand the Tables node and then select the ColorsCSV#csv node.

  9. In the Properties window, change the value for the Access Method to Random.

Run the Web Performance Test to Verify That the Loop Works Correctly

To Verify the Counting Loop

  1. In the Web Performance Test Editor, choose Run Test to start your web performance test and display the Web Performance Test Results Viewer.

  2. In the Web Performance Test Results Viewer there will be eight loop iterations of the web request that you added the counting loop to. These iterations randomly select either the red or the blue ASP pages.

    Note

    You might have to scroll up in the Web Performance Test Results Viewer to see all the loop iterations.

    Note

    The errors in the test are caused by the response URL validation rule because the URL does not match the URL that was recorded. You can remove this validation error by deleting the Response URL validation rule under the Validation Rules node in the Web Performance Test Editor. For more information, see Using Validation and Extraction Rules in Web Performance Tests.

See Also

Tasks

How to: Add a Validation Rule to a Web Performance Test

Concepts

Binding a Data Source to a Web Performance Test

Web Performance Test Walkthroughs

Other Resources

Adding Loop and Branch Logic to Web Requests in Web Performance Tests

Adding Loop and Branch Logic to Web Requests in Web Performance Tests