Walkthrough: Recording and Running a Web Test
In this walkthrough, you will create a Web test from a browser recording and verify that it works correctly.
This walkthrough steps you through the creation and running of a Web test using the tools of Visual Studio Team System Test Edition. A Web test starts as a list of URLs, representing Web requests, in the Web Test Editor. You create a Web test by recording a browser session using the Web Test Editor. For more information about Web tests, see Working with Web Tests.
In this walkthrough, you will perform the following tasks:
Create a test project
Create a Web test from a browser recording
Run the Web test to verify that it works correctly
To complete this walkthrough, you need the following:
The Web application that you created in Walkthrough: Creating a Simple Web Application
For this walkthrough you will not make any changes to the Web application that you created in Walkthrough: Creating a Simple Web Application, but you will need the address of the application.
To prepare for the walkthrough
Open the Web application that you created in Walkthrough: Creating a Simple Web Application.
Press CTRL+F5 to run the Web application in the browser. You should see the first page.
This starts the ASP.NET Development Server that runs the Web application your Web test will test. You will see the ASP.NET Development Server icon in the notification area, at the far right of the taskbar.
Copy the address of your Web application to the clipboard or a notepad file. For example, the address might look like this: http://localhost:<PortNumber>/ColorWebApp/Default.aspx
Close the browser, but leave the Web application open.
To create the test project
In a new instance of Visual Studio, on the File menu, point to New and then click Project.
The New Project dialog box appears.
Under Projects, expand Visual Basic or Visual C# according to your preference, and select the Test node.
You will not write any code in this walkthrough. The language you choose for your project affects the language that is used when coded Web tests are generated.
Under Visual Studio installed templates, choose Test Project.
In the Name box, type ColorWebAppTest.
In the Location box, type the name of the folder where you saved your Web application. For example, type the folder name C:\WebSites\ColorWebApp.
Clear the Create directory for solution check box.
By default, Visual Studio will add a unit test file and a text file that has information about authoring tests. You will not need these files for this walkthrough, so that you can delete them. If you do not delete the files, they will not affect the walkthrough.
You record a Web test by browsing a Web site as if you were the end user. As you move through the site, requests are recorded and added to the Web test. For more information about how to record a Web test, see How to: Record a Web Test.
To record the Web test
On the Test menu, click New Test.
The Add New Test dialog box appears.
In the Add New Test dialog box, select Web Test, name the test ColorWebTest.webtest, and click OK.
A new Web test file named ColorWebTest.webtest is added to your project, and the Web Test Recorder opens inside a new instance of Internet Explorer.
In the browser's address bar, type the address of the Web application that you copied in a previous step, and press enter.
Visual Studio begins to display the Web test URLs in the Web Test Recorder as it is recording.
Choose Red and click Submit; the page with the Label that says Red should be displayed.
Go back to the first page.
Choose Blue and click Submit; the page with the Label that says Blue should be displayed.
Go back to the first page.
In the browser's address bar type the address of an external Web site. For example, type http://www.contoso.com.
Go back to the first page.
Click Stop on the Web Test Recorder to stop recording.
A dialog box displays the message Detecting dynamic parameters. It also displays a progress bar that shows the status of parameter detection in the HTTP responses that were received.
If no dynamic parameters are detected, the dialog box displays the message Did not detect any dynamic parameters to promote. The dialog box then closes.
If dynamic parameters are detected, the Promote Dynamic Parameters to Web Test Parameters dialog box appears.
(Optional) In the Promote Dynamic Parameters to Web Test Parameters dialog box, select check boxes for the promotions that you want to apply when you run the Web test, and click OK.
Now that recording has ended, you can see your Web test in the Web Test Editor as a list of URLs. You can now edit the test.
Choose File and then choose Save ColorWebTest.webtest to save the newly recorded Web test.
The tree of URLs in the Web Test Editor is called the request tree. You can select various nodes in the request tree to view the properties associated with each request.
To view request properties
In the Web Test Editor, go to the request tree and select http://www.contoso.com.
In the Properties window, note the values of the different properties, for example URL, Follow Redirects and Think Time.
Notice that Think Time for this request is 0.
In the Web Test Editor, go to the request tree and select the last entry before the http://www.contoso.com entry.
Notice that Think Time for this request is greater than 0, for example 30 seconds. This is the time it took you to enter http://www.contoso.com in the browser's address bar.
You can now run the Web test to verify it that it works correctly. Each Web request you recorded will be replayed, and the results will be collected. For more information, see Running and Viewing a Web Test.
To verify the Web test
In the Web Test Editor, click Run Test on the toolbar.
The test starts to run, and a Web Test Viewer displays each request in the test. A Test Results window displays the result for the entire test. Next, you will verify the results.
In the Web Test Viewer select the first request in the list.
You should see a green check mark to the left of the request. A green check mark indicates that the request succeeded. You should see the first page of the Web application in the bottom pane.
In the Web Test Viewer select the request to http://www.contoso.com.
You should see either a green check mark or a red X to the left of the request. A red X indicates that the request failed. This will cause the result for the entire test to fail, after the test has finished. By default, if a request fails, the rest of the test is not aborted and does continue. For example, the external Web request to http://www.contoso.com might have failed because of firewall problems. However, the request after that, for Default.aspx, was still made and succeeded.
If you are unable to access Web sites outside your local network, you might have to specify a proxy server in your Web test. This is described in detail in the next section.
To run your test a second time, click Click here to run again at the top of the Web Test Editor.
If you are testing a Web site outside your firewall, you might receive the following error message when you run your test:
RequestFailed: The following error occurred which may indicate you have to configure a proxy server in your Web test: The remote name could not be resolved.
Your Web test probably contains external URLs like http://www.contoso.com. If you use a proxy to access Web sites outside your firewall, you must manually set the proxy property on the Web test to the proxy server that your browser uses to view Web pages. Set the proxy using the Web Test Editor.
To specify a proxy server
In the Web Test Editor go to the request tree and select the root node. The root node will be the name of the Web test, ColorWebTest.
In the Properties window, find the Proxy property and enter a valid proxy name. Ask your network administrator for a valid proxy name, or enter "default" to use Internet Explorer's proxy settings.
Using "default" as your proxy setting can cause performance problems when you run your Web test under load. It is better to specify a proxy other than "default" when you run your Web test in a load test.
Click Run Test on the toolbar to re-run the test.
In this walkthrough you recorded and ran a Web test. Now that you have a Web test, you can add either of the following enhancements, if they are needed:
To add data binding to your Web test, see Walkthrough: Adding Data Binding to a Web Test.
To add validation and extraction rules to your Web test, see Walkthrough: Adding Validation and Extraction Rules to a Web Test.
Finally, to convert your Web test to a coded Web test, see Walkthrough: Creating a Coded Web Test.