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.
To complete this walkthrough, you need the following:
Visual Studio Team System Test Edition
The Web application that you created in Walkthrough: Creating a Simple Web Application
The Web test that you created in Walkthrough: Recording and Running a Web Test
Open the Web application you created in Walkthrough: Creating a Simple Web Application.
Press CTRL+F5 to run the Web application in the browser. You should see the first page. Close the browser.
Anteckning
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.
Open the Web application you created in Walkthrough: Recording and Running a Web Test.
In Solution Explorer, double-click ColorWebTest.webtest. The Web Test Editor appears and the list of Web requests is displayed.
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.
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 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.
Right-click the Web request and choose Add Validation Rule.
The Add Validation Rule dialog box is displayed.
In the Select a rule pane, choose Find Text.
In the Properties pane, set the Find Text property to Red, and set the Pass If Text Found property to True.
Click OK.
On the File menu click Save ColorWebTest.webtest 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 for the page Red.aspx.
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.
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.
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 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.
Right-click the Web request and then choose Add Extraction Rule.
The Add Extraction Rule dialog box is displayed.
In the Select a rule pane, choose Extract Attribute Value.
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
Click OK.
Choose File and then 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 for the page Blue.aspx.
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 value extracted by the rule, color:Blue;.
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.
Walkthrough: Creating a Simple Web Application
Walkthrough: Recording and Running a Web Test
Walkthrough: Adding Data Binding to a Web Test