Export (0) Print
Expand All

How to: Add Loops to Web Performance Tests Requests

This topic applies to:

Visual Studio Ultimate

Visual Studio Premium

Visual Studio Professional 

Visual Studio Express

Topic appliesTopic does not applyTopic does not applyTopic does not apply

To simplify testing, you can add loop logic to Web performance tests or to Web requests. By specifying conditional rules and properties, you can run a Web request multiple times to verify if any of the specified conditions are met. For example, you could create a loop condition that runs thousands of times and verifies if a numeric comparison is met, such as the value of a context parameter being greater than zero.

Considerations for Using Loops

Consider the following potential issues when you use loops in a Web performance test or a load test that uses 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 is possible that some users might add several items to a shopping cart while shopping in a single session but that will 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 user hundreds of times. When possible, use less than 10 iterations in your loops.

Adding Conditional Rule and Items to a Loop

Adding a loop

Add conditional rule and items to a loop
NoteNote

You can also add branching conditional logic, which verifies if a condition in a Web performance test is true or false. For more information, see How to: Add "If Then" Branch Conditions to Web Performance Tests Requests.

To insert a loop with conditional rules

  1. Open a solution that contains a test project and make sure that the test project contains a Web performance test. Then open the Web performance test.

  2. Select either the Web performance test or the Web request where you want to insert a loop. Right-click and select Insert Loop.

  3. In the Add Conditional Rule and Items to Loop dialog box, under Select a rule, choose the type of conditional rule that you want to use in the loop. The following table lists the descriptions of the different types of conditional rules and their associated properties that are available.

  4. Next, under Properties for selected rule, specify the property settings that you want.

    For example, you could select a Counting Loop rule and set its Number of Iterations property value to 10000. As a result, the specified Web request will run 10000 times.

    The Max Number of Iterations property is set with a default value of -1. You can set a value for this as a failsafe to prevent infinite loops. The -1 setting specifies that there is no maximum number of iterations.

    NoteNote

    The descriptions for the conditional rules and associated properties are also displayed in the Add Conditional Rule and Items to Loop dialog box. As with the Properties window, you can use the properties toolbar buttons in the Add Conditional Rule and Items to Loop dialog box to sort the properties by Categorized, Alphabetical and by Property Pages.

    Conditional Rules and Associated Properties

    Conditional Rule

    Rule Description

    Properties

    Context Parameter Existence

    Verify the existence or absence of a context parameter.

    • Context Parameter Name

    • Check for Existence

    Cookie Existence

    Verify the existence or absence of a cookie.

    • Web Page URI

    • Cookie Name

    • Verify for Existence

    • Cookie Domain Name (optional)

    • Cookie Path (optional)

    Cookie Value Comparison

    The condition is met when the provided string matches the value of the specified cookie.

    • Web Page URI

    • Cookie Name

    • Comparison Operator

    • Value

    • Ignore Case

    • Use Regular Expression

    • Cookie Domain Name (optional)

    • Cookie Path (optional)

    For Loop

    The rule represents a traditional "for" loop. The context parameter is initialized before the first loop iteration. The loop statements are executed while the content of the context parameter satisfies the comparison with the provided value. The step value is applied at the end of each loop iteration.

    • Context Parameter Name

    • Comparison Operator

    • Terminating Value

    • Initial Value

    • Increment Value

    Number Comparison

    The condition is met when the content of the provided context parameter satisfies the numeric comparison with the provided value.

    • Context Parameter Name

    • Comparison Operator

    • Value

    Probability Rule

    The condition will be considered as met according to the provided percentage.

    • Context Parameter Name

    • Percentage

    Counting Loop

    Executes the requests contained in the loop a specified number of times.

    • Context Parameter Name

    • Number of Iterations

    String Comparison

    The condition is met when the provided string matches the content of the provided context parameter.

    • Context Parameter Name

    • Comparison Operator

    • Value

    • Ignore Case

    • Use Regular Expression

  5. Under Items in Loop, use the drop-down list under Choose first item for loop to specify the first item that you want to use in the loop.

  6. Click the drop-down list under Choose the last item for loop to specify the last item that you want to use in the loop.

  7. Click OK.

    After you have closed the Add Conditional Rule and Items to Loop dialog box, your loop is now indicated by an icon in the Web Performance Test Editor.

    NoteNote

    Later, you can edit the property settings that you specified for the rule by selecting the loop in the Web Performance Test Editor and using the Properties window.

Community Additions

ADD
Show:
© 2014 Microsoft