This documentation is archived and is not being maintained.

Walkthrough: Adding Data Binding to a Web Test

In this walkthrough, you will add data binding to a Web test and verify that it works correctly.

By using data binding, a database can provide data for a Web Test. You can bind data from a data source to a part of a Web request that requires data, such as a form post parameter. For more information, see About Data Binding in Web Tests.

In this walkthrough, you will perform the following tasks:

  • Add data binding to a Web test

  • Run the Web test to verify that it works correctly

To complete this walkthrough, you need the following:

For this walkthrough, you will need a sample data source to bind to. We will create a simple text file data source.

To prepare the data source

  1. Create a new folder and name it Data.

  2. In the Data folder, create a new text file and name it ColorData.


    You can use any text editor, for example Notepad, to create the file.

  3. Add the following to the text file:

    ColorId, ColorName
  4. Save and close the file.

To prepare the Web test

  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 will see the first page. Close the browser.


    This starts the ASP.Net Development Server that runs the Web application your Web test will test. You will see the ASP.Net Development Server icon in the notification area, at the far right of the taskbar.

  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.

To add data binding your Web test

  1. In the Web Test Editor, right-click the top node of your Web test and then click Add Data Source.

  2. In the drop-down list labeled OLE DB Provider, select Microsoft Jet 4.0 OLE DB Provider.

  3. In the Server or file name text box, type the path of your Data folder.

    Caution noteCaution

    Specify the name of the folder, not the file itself.

  4. Click Advanced.

    The Advanced Properties dialog box is displayed.

  5. Locate the Extended Properties property and type Text.

  6. Click OK to close the Advanced Properties dialog box.

  7. (Optional) Click the Test Connection button to verify your connection to the file.

  8. Click OK to close the Connection Properties dialog box.

    The Choose Tables dialog box is displayed.

  9. In the Choose Tables dialog box, select the ColorData#txt file.


    If you have more than one text file in the data folder, you can select all the files that you want to use. Each file is treated as a table. The period (.) in the text file name will be replaced by a number sign symbol (#), for example ColorData#txt.

  10. Click OK to close the Choose Tables dialog box.

    A Data Sources node will be added to your Web test, and the text file will appear as a table in the hierarchy.

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


    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.

  12. Select the RadioButtonList1 node.

  13. In the Properties window, find the Value property. It is currently set to Red because that is what you selected when you recorded the Web test. Click the property, and then click the down arrow that appears.

  14. Expand DataSource1, expand the Colors table, and then select ColorName. The RadioButtonList is now data bound to the database.

  15. On the Test menu point to Edit Test Run Configurations, and then click Local Test Run.

  16. In the localtestrun.testrunconfig dialog box, select Web Test in the left pane, and then select the One run per data source row option in the right pane. This causes the test to run iteratively, one time for each row in the database. On each test iteration, the cursor moves to the next row in the database.

  17. Click Apply and then click Close.

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

To verify the Web test

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

  2. In the Web Test Viewer there will be two runs of the Web test. Run 1 will use the first row of data, and Run 2 will use the second row of data. Notice that Run 1 visits the page Red.aspx, and Run 2 visits the page Blue.aspx.


    You might have to scroll up in the Web Test Viewer to see both test runs.

In this walkthrough you added data binding to a Web test.

To add validation and extraction rules to your Web test, see Walkthrough: Adding Validation and Extraction Rules to a Web Test. Finally, to convert your Web test to a coded Web test, see Walkthrough: Creating a Coded Web Test.