How to use a list of values for a parameter?

The simple answer is do a web search for data driving (or data driven) Visual Studio web performance tests. You should find many articles and tutorials.

In more detail:

Outline of how to data drive a test

Firstly, Visual Studio distinguishes different types of test. A Load Test is a way of running individual test cases many times, as if by many simultaneous users, gathering data about the test executions and producing a report. The test cases that a load test can execute include Web Performance Tests and Coded UI Tests; both of these can be data driven.

Data driving a Web Performance Test requires a data source. The data can be CSV, XML, Spreadsheet, database and in TFS. I will describe using CSV.

Create a CSV file, containing something similar to the following. Note that the top line of field names is required and those names are used within the test.

Name,Email,Telephone
Fred,[email protected],0123 456789
George,[email protected],0123 456790
Harry,[email protected],0123 456791

See also CodedUI test does not read data from CSV input file for some notes CSV file creation.

Open the test project in Visual Studio and open the .webtest file for the test. Use the context (right-click) menu of the top node of the test, ie the test’s name (or use the corresponding icon) and select “Add data source …”. Follow the prompts to add the CSV file into the project.

Within the Web Performance Test expand the request to show the form parameters or query string or whatever that is to use the data. View the properties panel of the relevant field and select the appropriate property, in many cases it is the Value property. Click the little triangle for choosing a value for the property. The popup should show the data source, expand the items shown and select the required field. After selecting the field the property will show a value such as {{DataSource1.FileName#csv.Email}}. The doubled curly braces ({{ and }}) indicate the use of a context parameter. All the used data source fields are available as context parameters. All of the data source fields can be made available by altering the Select Columns property of the data source file. Data source field can be used as part of a property value by using values such as

SomeText{{DataSource1.FileName#csv.Email}}AndMoreText

Data source access methods

The data from the datasource can be read and used in four ways. The default is Sequential. Other orders are selected using Solution Explorer to access the properties of the file (eg FileName#csv). The Access Method property can be set to one of:

Sequential data is read sequentially through the file. After the last line of the file is read, the first line of the file will be next line to be read. Thus each line may be read more than once.

Random data is read randomly.

Unique data is read sequentially through the file. After the end of the file is read the test will not be executed again. Thus each line in can only be read once.

Do not move cursor automatically intended for more complex tests where the cursor is moved via calls from plugins.

A web test may use more than one data source file. These files may have different access methods. For example one file containing login names and passwords could be accessed Sequentially and another file with other data could be accessed Randomly. This would allow each login to try many different sets of the other data.

Data sources and loops

Web performance tests may contain loops. The properties of a loop include Advance data cursors. This allows, for example, a data source file to contain items to be found and added to a shopping basket such that each loop iteration adds a new item.

Leave a Comment