How to: Add Data Binding to a Web Test

You can use data binding in a Web test to let a database serve as the source for the user inputs to the HTTP request in the Web test. For example, you could store a list of logon names and logon passwords that would then be used during the execution of the Web test to try repeated logons.

You can examine your tests and decide which part of a test you want to be data-driven. Then you can create a data source, such as an Access database, for that part of the test. You can bind data in several locations in a Web test. For more information, see About Data Binding in Web Tests.

To add data binding the Web test

  1. Open a Web test.

    The Web Test Editor is displayed.

  2. In the Web Test Editor, click the Add Data Source button.

  3. From the drop-down list labeled OLE DB Provider, select an appropriate provider.

  4. Click the Data Links button, and locate your data file. Click Open.

  5. Click the Test Connection button to verify your connection to the file, and then click OK.

  6. In the Choose tables dialog box, select the name of the table in the database. Click OK.

  7. Find a request in the request tree that requires this data in one of the nodes, such as a request with a Form Post parameter. Select the parameter node.

  8. In the Properties window, click the drop-down arrow in the Value property and select the correct DataSource in the hierarchy. Next, select the name of the table and the name of the field to use as the value.

    The Web test is now bound to the data source.

To configure data binding in the Web test

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

    Note

    Instead of editing the Local Test Run configuration, you can also create a separate data run configuration for testing your data binding. Then you can switch between run configurations. For more information, see How to: Specify a Test Run Configuration.

  2. In the localtestrun.testrunconfig dialog box, select Web Test in the left pane, and then select either the One run per data source row option or the Fixed run count option in the right pane.

    This causes the test to run iteratively, either one time for each row in the database or for a fixed number of rows. On each test iteration, the pointer moves to the next row in the database.

  3. Click Apply and then click Close.

  4. On the File menu, menu click Save to save the Web test.

Data Binding in Web Service Tests

To add data binding to a Web service test, you must change the SOAP XML manually. For more information, see How to: Create a Web Service Test.

To add data binding to a Web service test

  1. Open a Web test that contains a Web service request.

    The Web Test Editor is displayed.

  2. Find a Web service request in the request tree that you want to bind to a data source. Select the String Body node under it.

  3. In the Properties window, click the ellipsis (…) in the String Body property.

    The Edit HTTP Body String window appears.

  4. Replace values in the SOAP body with data bound values by using the folllowing syntax:

    {{DataSourceName.TableName.ColumnName}}
    
  5. For example, if you have the following code:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
            <CheckStatus xmlns="https://tempuri.org/">
                <userName>string</userName>
                <password>string</password>
                <orderID>int</orderID>
            </CheckStatus>
        </soap:Body>
    </soap:Envelope>
    

    You can change it to the following:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
            <CheckStatus xmlns="https://tempuri.org/">
                <userName>{{DataSourceName.Users.Name}}</userName>
                <password>{{DataSourceName.Users.Password}}</password>
                <orderID>{{DataSourceName.Orders.OrderID}}</orderID>
            </CheckStatus>
        </soap:Body>
    </soap:Envelope>
    
  6. Click OK to close the Edit HTTP Body String window.

  7. On the File menu, click Save to save the Web test.

See Also

Tasks

Walkthrough: Adding Data Binding to a Web Test
How to: Bind a Web Test to a Text File

Concepts

Overview of Data-Driven Unit Tests