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

To complete this walkthrough, you need the following:

To prepare for the walkthrough

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

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

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

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

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

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

    Note 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, choose Build Solution.

    The new code compiles.

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("http://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("http://msdn.microsoft.com/")
        MyBase.Send(customRequest)
    End If
    

  3. On the Build menu, choose Build Solution.

To verify the Web performance test

  1. With the coded Web performance test selected in the code editor, open the shortcut menu and choose Run Coded Web Performance Test.

    Caution note Caution

    If you follow these steps in Solution Explorer instead of the code editor, all of the tests run instead of just the selected test.

  2. The coded Web performance test runs and the results begin to appear in the Web Performance Test Results Viewer. For more information, see Web Performance Test Results Viewer Overview and Examining Web Performance Test Results Using the Web Performance Test Results Viewer.

  3. In the Web Performance Results Viewer, you can run your coded Web performance test again by choosing the Choose here to run again link on the embedded status bar.

    Tip Tip

    Before you run your test again, you can modify the number of iterations, network type, or browser type by changing the run settings. For more information, see How to: Change the Web Performance Test Run Settings in the Web Performance Result Viewer.

Show: