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

Prerequisites

To complete this walkthrough, you need the following:

Preparing for the Walkthrough

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

  1. Open the Web application that you created in Walkthrough: Creating a Simple Web Application.

  2. Press CTRL+F5 to run the Web application in the browser. You should see the first page.

    Note

    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.

  3. Copy the address of your Web application to the clipboard or a notepad file. For example, the address might look like this: https://localhost:<PortNumber>/ColorWebApp/Default.aspx

  4. Close the browser, but leave the Web application open.

Creating a Test Project

To create the test project

  1. In a new instance of Visual Studio, on the File menu, point to New and then click Project.

    The New Project dialog box appears.

  2. Under Projects, expand Visual Basic or Visual C# according to your preference, and select the Test node.

    Note

    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.

  3. Under Visual Studio installed templates, choose Test Project.

  4. In the Name box, type ColorWebAppTest.

  5. 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.

  6. Clear the Create directory for solution check box.

  7. Click OK.

    Note

    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.

Recording a Web Test

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

  1. On the Test menu, click New Test.

    The Add New Test dialog box appears.

  2. 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.

  3. In the browser's address bar, type the address of the Web application that you copied in a previous step, and press enter.

    Note

    Visual Studio begins to display the Web test URLs in the Web Test Recorder as it is recording.

  4. Choose Red and click Submit; the page with the Label that says Red should be displayed.

  5. Go back to the first page.

  6. Choose Blue and click Submit; the page with the Label that says Blue should be displayed.

  7. Go back to the first page.

  8. In the browser's address bar type the address of an external Web site. For example, type https://www.contoso.com.

  9. Go back to the first page.

  10. 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.

  11. (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.

  12. Choose File and then choose Save ColorWebTest.webtest to save the newly recorded Web test.

Viewing Request Properties

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

  1. In the Web Test Editor, go to the request tree and select https://www.contoso.com.

  2. In the Properties window, note the values of the different properties, for example URL, Follow Redirects and Think Time.

  3. Notice that Think Time for this request is 0.

  4. In the Web Test Editor, go to the request tree and select the last entry before the https://www.contoso.com entry.

  5. Notice that Think Time for this request is greater than 0, for example 30 seconds. This is the time it took you to enter https://www.contoso.com in the browser's address bar.

Running the Web Test to Verify that it Works Correctly

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

  1. 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.

  2. 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.

  3. In the Web Test Viewer select the request to https://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 https://www.contoso.com might have failed because of firewall problems. However, the request after that, for Default.aspx, was still made and succeeded.

    Note

    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.

  4. To run your test a second time, click Click here to run again at the top of the Web Test Editor.

Specifying a Proxy Server

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 https://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

  1. 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.

  2. 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.

    Warning

    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.

  3. Click Run Test on the toolbar to re-run the test.

Next Steps

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:

Finally, to convert your Web test to a coded Web test, see Walkthrough: Creating a Coded Web Test.

See Also

Tasks

How to: Record a Web Test

How to: Set Think Times in a Web Test

Walkthrough: Creating a Simple Web Application

Walkthrough: Adding Data Binding to a Web Test

Walkthrough: Adding Validation and Extraction Rules to a Web Test

Walkthrough: Creating a Coded Web Test