Data Driven Web Tests with VSTS2008
Recently, I was asked if a recorded WebTest can be link to the external datasource for data feed. For example if we would like to pass different search parameters into a search page to test the logic and data of the search, we definitely do not want to have multiple tests that do the same thing. It totally make sense to have a single test that will feed different data and will aggregate/reports results back to us.
My second attempt at the webcasting runs through example on how to accomplish data bounding to the web test:
Visual Studio Team System Testers Edition has an option of recording a Web Test, once the test is created we can easily add a data source to it, by doing following steps:
1. Right Click on the web test, Select Add Data Source.
From here you will a Wizard with multiple choices:
I think that you may want to use CSV,XML types:
- if you want BA or End Users to easily provide you with a test data
- if the amount of data is small
- you need a version history of data evolution (the file can be checked in into Source Control and deployed as part of the build process).
The Database choice is good:
- large amount of data (thousand/million data points).
- re-use the same data across multiple test/projects/teams/environments.
Once the data source is created, all is left is to replace hard coded values for the data from bound source.
2. Find a Post Parameter by expanding Request Form Post Parameter
3. Select Properties by Right Click on ContentPlaceHolder
4. Select created DataSource by Clicking on the drop down menu of the Value property.
5. Expand Datasource and Navigate to the needed column.
This is it, you know can run web test and feed the data from the external source.
But what if you want to add Validation and Extraction rules to your test and be able to run positive and negative tests, how do you do it with external data source?
You may take a similar approach and try to bind the value properties of the rules to data source, but you may run into a problem of setting the "Pass if Found" Boolean property.
In my opinion it would be better to convert the test to coded version and then you will have control over all aspects of the test.
6. Select Generate Code by right Clicking on the web test.
7. Make changes to the "PassIfFound" property of the rule.
Web Test Coded file from my demo can be downloaded from here