Partager via


Add a data source to a web performance test

Bind data to provide different values to the same test, for example, to provide different values to your form post parameters.

Binding data to a web performance test

We’re going to use a sample ASP.NET app. It has three .aspx pages – the default page, a Red page, and a Blue page. The default page has a radio control to choose either red or blue and a submit button. The other two .aspx pages are very simple. One has a label named Red and the other has a label named Blue. When you choose submit on the default page, we display one of the other pages. You can create an app like that, download our sample, or just follow along with your own web app.

Running the web app to be tested

Your solution should also include a web performance test that browses through the pages of the web application similar to the ColorWebAppTest project created in Record and run a web performance test [redirected].

Solution with web performance test

Create a SQL database

  1. If you don’t have Visual Studio Ultimate, get it here.

  2. Create a SQL database.

    Add a new SQL database

  3. Create a database project.

    Create new project from database

  4. Add a table to the database project.

    Add a new table to the database project

  5. Add fields to the table.

    Add fields to the table

  6. Publish the database project.

    Publish database project from Solution Explorer

  7. Add data to the fields.

    Add data to the fields

Add the data source

  1. Add a data source.

    Add data source to web performance test

  2. Choose the type of data source and name it.

    Name the database source

  3. Create a connection.

    Choose new connection

    Enter the connection details.

    Enter the SQL database connection properties

  4. Select the table that you want to use for your test.

    Add the Color table as the data source

    The table is bound to the test.

    Data Sources node add to the web performance test

  5. Save the test.

Bind the data

  1. Bind the ColorName field.

    Bind the ColorName field to RadioButtonList1 value

  2. Open the Local.testsettings file in Solution Explorer and select the one run per data source row option.

    Edit the test settings file

  3. Save the web performance test.

Run the test with the data

  1. Run the test.

    Run the web performance test to verify binding

    The two runs are displayed for each data row. Run 1 sends a request for the page Red.aspx, and Run 2 sends a request for the page Blue.aspx.

    Test run results

    When you bind to a data source, you could violate the default response URL rule. In this case, the error in Run 2 is caused by the rule which expects the Red.aspx page from the original test recording, but the data binding now directs it to the Blue.aspx page.

  2. Correct the validation error by deleting the Response URL validation rule and running the test again.

    Delete the response URL validation rule

    The web performance test now passes using data binding.

    Test passes using data binding

Q & A

Q: What databases can I use as a data source?

A: You can use the following:

  • Microsoft SQL Azure.

  • Any version of Microsoft SQL Server 2005 or later.

  • Microsoft SQL Server database file (including SQL Express).

  • Microsoft ODBC.

  • Microsoft Access file using the .NET Framework provider for OLE DB.

  • Oracle 7.3, 8i, 9i, or 10g.

Q: How do I use a comma separated value (CSV) text file as a data source?

A: Here's how:

  1. Create a folder to organize your projects database artifacts and add an item.

    Add new item to the Data folder

  2. Create a text file.

    Name the new text file ColorData.csv

  3. Edit the text file and add the following:

    ColorId, ColorName
    0,Red
    1,Blue
    
  4. Use the steps in Binding the SQL data, but choose CSV file as your data source.

    Enter a name and choose CSV file

Q: What if my existing CSV file does not contain column headers?

A: If you can’t add column headers, you can use a schema description file to treat the CSV file as a database.

  1. Add a new text file named schema.ini.

    Add a schema.ini file

  2. Edit the schema.ini file to add the information that describes the structure of your data. For example, a schema file describing the CSV file might look like this:

    [testdata.csv]
    ColNameHeader=False
    
  3. Add a data source to the test.

    Add data source to web performance test

  4. If you’re using a schema.ini file, choose Database (not CSV file) as the data source and name it.

    Add database data source

  5. Create a new connection.

    Choose new connection

  6. Select the .NET Framework Data Provider for OLE DB.

    Select the .NET framework OLE DB data provider

  7. Choose Advanced.

    Choose Advanced

  8. For the Provider property, select Microsoft.Jet.OLEDB.4.0, and then set Extended Properties to Text;HDR=NO.

    Apply advanced properties

  9. Type the name of the folder that contains the schema file and test your connection.

    Enter the path to the data folder

  10. Select the CSV file that you want to use.

    Select the text file

    After you finish, the CSV file appears as a table.

    Data source added to test

Q: How do I use an XML file as a data source?

A: Yes.

  1. Create a folder to organize your projects database artifacts and add an item.

    Add new item to the Data folder

  2. Create an XML file.

    Add ColorData.xml file

  3. Edit the XML file and add your data:

    <?xml version="1.0" encoding="utf-8" ?>
    <ColorData>
        <Color>
            <ColorId>0</ColorId>
            <ColorName>Red</ColorName>
        </Color>
        <Color>
            <ColorId>1</ColorId>
            <ColorName>Blue</ColorName>
        </Color>
    </ColorData>
    
  4. Use the steps in Binding the SQL data, but choose XML file as your data source.

    Enter a name and choose XML file

Q: Can I add data binding to a web service request that uses SOAP?

A: Yes, you must change the SOAP XML manually.

  1. Choose the web service request in the request tree and in the Properties window, choose the ellipsis (…) in the String Body property.

    Edit the web service string body

  2. Replace values in the SOAP body with data bound values by using the following syntax:

    {{DataSourceName.TableName.ColumnName}}
    

    For example, if you have the following code:

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

    You can change it to this:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
            <CheckStatus xmlns="http://tempuri.org/">
                <userName>{{DataSourceName.Users.Name}}</userName>
                <password>{{DataSourceName.Users.Password}}</password>
                <orderID>{{DataSourceName.Orders.OrderID}}</orderID>
            </CheckStatus>
        </soap:Body>
    </soap:Envelope>
    
  3. Save the test.