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.
To add an extraction rule to a Web test
Open a Web test.
For more information about how to create a Web test, see Creating a Web Test.
In the Web Test Editor, select the request to which you want to add the extraction rule.
Right-click the request and select Add Extraction Rule.
The Add Extraction Rule dialog box is displayed.
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.
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.
Set the Attribute Name property to href and the TagName property to a.
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.
Click OK to close the Add Extraction Rule dialog box.
On the File menu click Save to save the Web test.
In the Web Test Editor, click Run to start your Web test.
The Web Test Viewer is displayed.
In the top pane of the Web Test Viewer, click the request to which you added the validation rule.
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.
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.