Local Data Driven Test
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 Test Views ribbon 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 Steps button in the Test Views ribbon 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 drop-down arrow for (Bindings) located under the Data Driven heading.
- Click the Text node in the displayed tree.
- Enter the name of the column from which to draw data into the text box. The syntax is $(ColumnName) - in our example we want the first and only column, so we'll enter $(Numbers).
- 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[
//Reference a column by index (zero based)
Pages.Bing.SbFormQText.Text = Data.ToString();
'Reference a column by name
Pages.Bing.SbFormQText.Text = Data(
'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.
Note: If the test executes too quickly to validate visually, click the Enable Annotation button and set the delay in milliseconds before executing. These are located in the Quick Execute ribbon.