Share via


Walkthrough: Creating a Coded Web Performance Test

In this walkthrough you will convert a recorded Web performance test into a coded Web performance test.

This walkthrough steps you through the conversion of an existing, recorded Web performance test into a coded Web performance test. A recorded Web performance test begins as a list of URLs that represent Web requests. A Web performance test can be converted to a code-based script. After a Web performance test has been converted to its coded format, looping and branching constructs can be added. After you convert the Web performance test to a coded Web performance test, you can edit that code like any other source code.

Note

You should add validation rules, extraction rules, and data binding to your Web performance test before you convert it to a coded Web performance test. You can add these to your coded Web performance test, but if you use the Web Performance Test editor to add them first, you will save you time and sample code will be generated for you when you convert the test.

In this walkthrough, you will perform the following tasks:

  • Create a coded Web performance test by converting a recorded Web performance test

  • Add new code to a Web performance test

  • Run the Web performance test to verify that it works correctly

Prerequisites

To complete this walkthrough, you need the following:

Preparing for the Walkthrough

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. Close the browser.

    Note

    This starts the ASP.NET Development Server that runs the Web application your Web performance test will test. You will see the ASP.NET Development Server icon in the notification area.

  3. Open the Web application that you created in Walkthrough: Recording and Running a Web Performance Test.

  4. In Solution Explorer, double-click ColorWebTest.webtest. The Web Performance Test Editor appears and the list of Web requests is displayed.

Creating a Coded Web Performance Test

To convert an existing Web performance test to a coded Web performance test

  1. Click the Generate Code button on the toolbar in the Web Performance Test Editor.

  2. Accept the default name in the dialog box and click OK.

    Note

    The default name will be the name of the test with the word Coded appended.

    A new file is created. A new window opens and the source code for the test is displayed.

  3. On the Build menu, click Build Solution.

    The new code compiles.

Adding Code to a Web Performance Test

To add code to a Web performance test

  1. Locate the Run() method if your test is in Visual Basic or the GetRequestEnumerator() method if your test is in C#. You will see code that corresponds to each Web request in the test.

  2. Scroll down to the end of the method, and after the code for the last Web request, add the following code:

    if (DateTime.Today.DayOfWeek == DayOfWeek.Friday)
    {
        WebTestRequest customRequest = new WebTestRequest("http://weather.msn.com/");
        yield return customRequest;
    }
    else
    {
        WebTestRequest customRequest = new WebTestRequest("https://msdn.microsoft.com/");
        yield return customRequest;
    }
    
    If DateTime.Today.DayOfWeek = DayOfWeek.Friday Then
        Dim customRequest As WebTestRequest = New WebTestRequest("http://weather.msn.com/")
        MyBase.Send(customRequest)
    Else
        Dim customRequest As WebTestRequest = New WebTestRequest("https://msdn.microsoft.com/")
        MyBase.Send(customRequest)
    End If
    
  3. On the Build menu, click Build Solution.

Running the Web Performance Test to Verify that it Works Correctly

To verify the Web performance test

  1. On the Test menu, click Windows and then click Test View.

  2. Right-click ColorWebTestCoded and select Run Selection.

    Note

    The progress of a coded Web performance test can be viewed just like a recorded Web performance test.

  3. In the Test Results window, right-click the test results and choose View Test Results Details.

  4. In the Web Performance Test Results Viewer, in the top pane, scroll to the last Web request. Verify that the correct Web site was chosen based on the current day.

See Also

Tasks

How to: Create a Coded Web Performance Test

Walkthrough: Creating a Simple Web Application

Walkthrough: Recording and Running a Web Performance Test

Walkthrough: Adding Data Binding to a Web Performance Test

Walkthrough: Adding Validation and Extraction Rules to a Web Performance Test