Share via


Walkthrough: Adding Validation and Extraction Rules to a Web Test

In this walkthrough, you will add validation and extraction rules to a Web test and verify that they work correctly.

Validation rules help verify that a Web application is working correctly by validating the existence of text, tags, or attributes on the page returned by a Web request. For more information, see About Validation Rules.

Extraction rules are similar to validation rules, but instead of just verifying data, they will extract the data and store the result in the Web test context. For more information, see About Extraction Rules.

In this walkthrough, you will perform the following tasks:

  • Add a validation rule to a Web test.

  • Verify the validation rule results.

  • Add an extraction rule to a Web test.

  • Verify the extraction rule results.

Prerequisites

To complete this walkthrough, you need the following:

Preparing for the Walkthrough

To prepare for the walkthrough

  1. Open the Web application you created in Walkthrough: Creating a Simple Web Application.

  2. Press CTRL+F5 to run the Web application in the browser. You should see the first page. Close the browser.

    Note

    This starts the ASP.Net Development Server that runs the Web application your Web test is going to test. You will see the ASP.Net Development Server icon in the notification area.

  3. Open the Web application you created in Walkthrough: Recording and Running a Web Test.

  4. In Solution Explorer, double-click ColorWebTest.webtest. The Web Test Editor appears and the list of Web requests is displayed.

Adding a Validation Rule to a Web Test

In this Web test, you selected the Red option and clicked submit. Now you will add a validation rule to verify that you actually go to the page Red.aspx.

To add a validation rule to the Web test

  1. In the Web Test Editor, find the request that redirects to the page Red.aspx. This should be the second node in the request list.

    Important noteImportant Note:

    The Web application uses a redirect to move from the page Default.aspx to the page Red.aspx. In the Web 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=Red.

  2. Right-click the Web request and choose Add Validation Rule.

    The Add Validation Rule dialog box is displayed.

  3. In the Select a rule pane, choose Find Text.

  4. In the Properties pane, set the Find Text property to Red, and set the Pass If Text Found property to True.

  5. Click OK.

  6. On the File menu click Save ColorWebTest.webtest to save the Web test.

Verifying Validation Rule Results

To verify the validation rule results

  1. In the Web Test Editor, click Run to start your Web test.

    The Web Test Viewer is displayed.

  2. In the top pane of the Web Test Viewer, click the request for the page Red.aspx.

  3. In the bottom pane of the Web Test Viewer, click the Details tab. The Validation and Extraction Rules grid is displayed with the results of the validation rule.

Adding an Extraction Rule to a Web Test

In this Web test, you selected the Blue option and clicked submit. Next you will add an extraction rule get the style of the Label on the page Blue.aspx.

To add an extraction rule to the Web test

  1. In the Web Test Editor, find the request that redirects to the page Blue.aspx. This should be the fourth node in the request list.

    Important noteImportant Note:

    The Web application uses a redirect to move from the page Default.aspx to the page Blue.aspx. In the Web Test Editor, the request list will show Default.aspx, not Blue.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=Blue.

  2. Right-click the Web request and then choose Add Extraction Rule.

    The Add Extraction Rule dialog box is displayed.

  3. In the Select a rule pane, choose Extract Attribute Value.

  4. In the Properties pane, set the following properties:

    Property

    Value

    Context Parameter Name

    ExtractionTest

    Tag Name

    span

    Attribute Name

    style

    Match Attribute Value

    Color:Blue

  5. Click OK.

  6. Choose File and then Save to save the Web test.

Verifying Extraction Rule Results

To verify the extraction rule results

  1. In the Web Test Editor, click Run to start your Web test.

    The Web Test Viewer is displayed.

  2. In the top pane of the Web Test Viewer, click the request for the page Blue.aspx.

  3. In the bottom pane of the Web Test Viewer, click the Details tab.

    The Validation and Extraction Rules grid is displayed with an entry for the extraction rule you just added.

  4. Click the Context tab.

    A grid of names and values is displayed. The last entry will be the value extracted by the rule, color:Blue;.

Next Steps

In this walkthrough you added validation and extraction rules to a Web test.

To add data binding to your Web test, see Walkthrough: Adding Data Binding to a Web Test. Finally, to convert your Web test to a coded Web test, see Walkthrough: Creating a Coded Web Test.

See Also

Tasks

Walkthrough: Creating a Simple Web Application

Walkthrough: Recording and Running a Web Test

Walkthrough: Adding Data Binding to a Web Test

Walkthrough: Creating a Coded Web Test

Concepts

About Validation Rules

About Extraction Rules