In this post we will follow step by step approach to bind data from a SQL Server table to perform data driven automated web testing.
Let us assume we have a SQL Server table and we want to use it as data source for automated web testing in Test Studio. Assume table schema is as following
And data in table is as below
Before using data from this table for automated web testing, we need to add database containing this table as data source and then we will have to bind the table to the test. Essentially we need to perform three steps,
- Add database as data source in test project
- Bind table to test
- Bind column to a particular Test step
Add database to project
To add database as data source to project click on Project tab and then click on Add Data Sources
Choose Database as type of data source
Select SqlClient Data Provider as Provider from then Provider drop down.
After selecting provider, we need to provide connection string of the database and a friendly name for the data source. Click on ok button to add SQL Server database as data source.
After adding data source you can see that added data source is being listed in the Data Source section.
Binding Table to a particular Test
Once data source is added to the test project, we can bind a particular table from data source to a test. To do that right clicks on test in which you want to do data binding. In below image we are binding to test named bingtest
You will be prompted to select data source. In drop down the entire data source added to the project would be listed.
From drop down select data source we added in previous step.
Once data source is selected one more drop down would get visible to select table. In this case there is only one table named BingSearch in the data source. Select the table from the drop down.
After selecting table all the records from table will be listed in Grid. Click on the Ok button to complete data binding task to a test.
You will notice a database icon next to test we done data binding.
Binding Columns to a Test Steps
To bind a column to a test step we need to select that particular test step in the Steps tab and from the properties tab select collection option
After selecting the step in the property tab navigate to Data Driven section
From the collection drop down, you need to select the column to bind to the step. Once column is selected, click on the Set button to complete the data binding.
You can verify in the test step that test property of that element is data driven now.
In this way you can perform data driven testing fetching data from a SQL Server table. I hope this post was useful. Thanks for reading.