Dela via


How to: Add "If Then" Branch Conditions to Web Performance Tests Requests

This topic applies to:

Visual Studio Ultimate

Visual Studio Premium

Visual Studio Professional 

Visual Studio Express

Topic applies Topic does not apply Topic does not apply Topic does not apply

You can add if/then branching logic to Web performance tests and then assign specific conditional rules and properties. For example, you could create a condition on a Web request to verify if a cookie is present.

Adding a Conditional Rule

Adding branch conditions to web testsAdding branch condition rules and properties

Note

You can also add looping conditional logic, which can run a Web performance test or a Web request in a Web performance test multiple times to verify if a condition is true or false. For more information, see How to: Add Loops to Web Performance Tests Requests.

To insert a conditional branch rule into a Web performance test

  1. Open a solution that contains a test project. Make sure that the test project contains a Web performance test and then open the Web performance test.

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

  3. In the Add Conditional Rule and Items to Condition dialog box, under Select a rule, choose the type of conditional rule you want to use in the if/then branching logic. For the descriptions of the different kinds of conditional rules that are available, see the table in this procedure.

  4. Under Properties for selected rule, specify the property settings according to your needs.

    For example, you could use the Last Response Code rule to verify that the response code is returning 200 - OK.

    The conditional rules and their associated properties are included in the table in this procedure.

    Note

    The descriptions for the conditional rules and associated properties are also displayed in the Add Conditional Rule and Items to Condition dialog box. As with the Properties Window, You can use the properties toolbar buttons in the Add Conditional Rule and Items to Condition 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

    Confirm the existence or absence of a context parameter.

    • Context Parameter Name

    • Check for Existence

    Cookie Existence

    Confirm the existence or absence of a cookie.

    • Web Page URI

    • Cookie Name

    • Check for Existence

    • Cookie Domain Name (Optional)

    • Cookie Path (Optional)

    Cookie Value Comparison

    The condition is met when the provided string matched 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)

    Last Request Outcome

    Confirm the outcome of the previous request.

    • Request Outcome

    Last Response Code

    Confirm the HTTP status code of the previous response

    • Comparison Operator

    • Response Code

    Numeric 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

    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 Condition, use the drop-down list under Choose first item for condition and specify the first item that you want to use in the condition.

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

  7. Click OK.

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

    Note

    Later, you can edit the property settings that you specified for the rule by highlighting the condition in the Web Performance Test Editor and using the Properties Window.

See Also

Tasks

How to: Edit an Existing Web Performance Test Using the Web Performance Test Editor

How to: Add Loops to Web Performance Tests Requests

Other Resources

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

Analyzing Load Test Runs