Let's create a new, Local Data Driven test. We'll go through five iterations of the test, each with a different search text.
- Create a new Web Test and click Record.
- Navigate to www.google.com, enter Telerik in the Google search box, and hit the Search button.
Click the Pause button in the docked IE toolbar.
Click the Local Data button in the bottom of the test or the Data tab in Visual Studio.
There are three buttons at the top of this pane. Only Create a new data table is enabled. Click it to add a new grid for data.
The default grid will have five columns. This example will execute five iterations of the test with different search text for each.
Change the columns text box to 1 and click Update.
Enter any text into the first grid cell and hit the Enter or Tab key. The input will move to the second row.
Continue entering text for the remaining grid cells. New rows are added as you type.
Right click Col1 and choose Rename Column. In this example, Numbers is the new name.
Save the test.
Data from an array can be used in recorded steps and code behind methods. To bind data from a data array to a recorded step, continue step 13. To use reference data from the data array in a code behind method, skip to step 22.
Click the Test Steps at the button of the test or the Step tab in Visual Studio to return to the Test Steps View
Highlight step 2. This is the recorded step that sets the value of the Google search text box.
The properties for this step appear in the Properties pane, located on the right of the screen.
Click the '...' button for (Bindings).
Choose the 'Numbers' from the drop down for Text.
Click the Set button.
The data for the column named Numbers from the data array is now bound to the Text property for that step. Instead of entering Telerik into the search box, the data stored in the array will be entered.
Save and execute the test. Note that the test will execute for each row in the data array, for a total of five iterations.
To use reference data from the data array in a code behind method, follow these steps.
Highlight step 2. This is the recorded step that sets the value of the Google search text box. Right click the step and select Customize Step in Code.
Choose Visual Basic or C#.
Use the Data property followed by the index of the column to reference data from the grid. For example:
//Reference a column by name Pages.Bing.SbFormQText.Text = Data["Numbers"].ToString(); //Reference a column by index (zero based) Pages.Bing.SbFormQText.Text = Data.ToString();
'Reference a column by name Pages.Bing.SbFormQText.Text = Data("Numbers").ToString() 'Reference a column by index (zero based) Pages.Bing.SbFormQText.Text = Data(0).ToString()
Save and build project.
Execute your test. Note that the test will be executed for each row in the data array.