How to use a list of values for a parameter?

吃可爱长大的小学妹 提交于 2019-11-27 09:53:48
AdrianHHH

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,fred@example.com,0123 456789
George,george@example.com,0123 456790
Harry,harry@example.com,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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!