Visual Studio 2008 introduces a new option called "Extract Web Test" within the Web Test context menu.
This is a cool feature that allows you to extract requests or transactions from a web test and create a new web test. I love this feature mainly because it can save us a lot of time and allow you to modular your tests…Let me explain.
One of the key features we need to strive for is to modular our automated tests. We want to be able to reuse modules or web tests within different tests or scenarios. For instance, think of the following scenario:
Lets say that your application supports two types of roles: Admin and Guest. You want to create a test for admin users scenario and another for guest users scenario. Both need to perform a login.
One option is to "repeat" test request in the admin scenario and in the guest scenario. You will record the login transaction twice, thus there will be twice as much test to maintain and remember that test == code.
Obviously it is wrong. So you would like to extract some requests into a web test and call this new web test from both scenarios. It should look something like this:
First I recorded all the user steps in a single action. The action include the login, the scenario and the logout. Notice: this way, we get the correlation of the parameters working for us.
Next we want to extract the request. Note I use notes to indicate where the login ends.
When we click OK, we get a new test in the solution and the current web test will add a web test call to that new test:
NOTE: When you use the extract option, you will get the parameters correlation and you will inherit all the rules and data sources.
Now keep in mind that it is possible for you to create a test based on other tests. You can achieve that by using the "Add Call To Web Test":
This will help you construct new tests fast and by reusing pieces of tests.