How to: Add an Extraction Rule to a Web Test

Extraction rules help verify that a Web application is working correctly by extracting data from the responses to Web requests. Extraction rules store results in the test context as name value pairs. Extraction rules can extract form fields, text, attributes, headers, regular expressions, and hidden fields. For more information, see About Extraction Rules.

You add extraction rules to Web tests in the Web Test Editor. For more information about opening and editing a Web test, see How to: Edit an Existing Web Test.

Procedure

To add an extraction rule to a Web test

  1. Open a Web test.

    For more information about how to create a Web test, see Creating a Web Test.

  2. In the Web Test Editor, select the request to which you want to add the extraction rule.

  3. Right-click the request and select Add Extraction Rule.

    The Add Extraction Rule dialog box is displayed.

  4. In the Add Extraction Rule dialog box, in the Select a rule pane, select a rule to configure. For example, select Extract Attribute Value. For information about other predefined extraction rules, see About Extraction Rules.

  5. In the Properties for selected rule pane, set the Context Parameter Name property to a descriptive name such as FirstLink. When the extraction rule runs, a context variable named FirstLink is created that contains the extracted string.

  6. Set the Attribute Name property to href and the TagName property to a.

    Note

    The HTML format of what we are trying to extract in this example is <a href=http://www.contoso.com>, where a is referred to as the tag and href is the attribute of interest.

  7. Click OK to close the Add Extraction Rule dialog box.

  8. On the File menu click Save to save the Web test.

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

    The Web Test Viewer is displayed.

  10. In the top pane of the Web Test Viewer, click the request to which you added the validation rule.

  11. 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.

  12. Click the Context tab.

    A grid of names and values is displayed. The last entry will be the FirstLink variable and its value. The value should match the first <a href> on the requested page. You can verify this by viewing the requested page in a browser, viewing the source of the page, and searching for the first href.

See Also

Tasks

How to: Create a Custom Extraction Rule

Walkthrough: Adding Validation and Extraction Rules to a Web Test

How to: Edit an Existing Web Test

Concepts

About Extraction Rules

Creating a Web Test