Bagikan melalui


Walkthrough: Creating a Web Performance Test that Requires a Login and Logout

In this walkthrough you create a simple Web application that contains a login step and a logout step. The application simulates a shopping application, but does not contain functional code. Finally, you create a Web performance test to test the application.

In this walkthrough, you will perform the following tasks:

  • Create a simple Web application.

  • Create a Web performance test.

  • Extract new Web performance tests from an existing Web performance test.

  • Compose a new Web performance test from existing Web performance tests.

Prerequisites

For this walkthrough you will need:

  • Visual Studio 2010 Ultimate

Creating the Web Application

To create the Web application

  1. In Visual Studio 2010 Ultimate, on the File menu, click File and then click Project.

    The New Project dialog box appears.

  2. Under Installed templates, expand the programming language you prefer and then click Web.

  3. In the list of Web project types, select Empty ASP.NET Application.

    Note

    You will write minimal code in this walkthrough.

  4. In the Name box, type ShoppingWebApp.

  5. In the Location box, specify the folder where you want to create your Web application.

  6. Select Create directory for solution.

  7. Click OK.

  8. On the Project menu, choose Add New Item.

    The Add New Item dialog box appears.

  9. In the list of items, choose Web Form.

  10. In the Name text box, type Default.aspx and then click Add.

To create the home page for the Web application

  1. In Solution Explorer, right-click Default.aspx and click View Designer.

    A blank page is displayed.

  2. If the toolbox is not visible, click View and then click Toolbox.

  3. From the Standard group, drag five buttons onto the page. Use the following table to complete this step.

    Note

    Double-click each button to open the button click event and add the code.

    Control

    Text Property

    Button Click Code

    Button1

    Go to Log In

    Response.Redirect("Login.aspx");

    Button2

    Product 1

    Response.Redirect("Product1.aspx");

    Button3

    Product 2

    Response.Redirect("Product2.aspx");

    Button4

    Shopping Cart

    Response.Redirect("Cart.aspx");

    Button5

    Go to Log Out

    Response.Redirect("Logout.aspx");
  4. On the File menu, click Save All.

To add pages to the Web application

  1. On the Website menu, click Add New Item.

  2. In the Add New Item dialog box, click the Web Form template, name it Login.aspx, and then click Add.

  3. At the bottom of the document window, click the Design tab to switch to design view.

  4. Drag a button onto the page.

  5. Drag a text box onto the page.

  6. Repeat steps 1 through 4 four more times. Use the following table to complete this step:

    Web Page

    Control

    Text Property

    Button Click Code

    Login.aspx

    TextBox1

    -

    -

    Login.aspx

    Button1

    Log In

    Response.Redirect("Default.aspx");

    Product1.aspx

    Button1

    Add to Cart

    Response.Redirect("Default.aspx");

    Product2.aspx

    Button1

    Add to Cart

    Response.Redirect("Default.aspx");

    Cart.aspx

    Button1

    Buy

    Response.Redirect("Default.aspx");

    Logout.aspx

    Button1

    Log Out

    Response.Redirect("Default.aspx");

    Note

    There is no real functionality in this Web application. Submitting each page returns the user to the home page. This functionality is sufficient for the purposes of this walkthrough.

  7. On the File menu, click Save All.

To test the Web application manually

  1. In Solution Explorer, right-click Default.aspx and then click Set As Start Page.

  2. Press CTRL+F5 to run the Web application in the browser. You will see the home page, Default.aspx.

    Note

    This starts the ASP.NET Development Server that runs the Web application that your Web performance 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 the Web application to the clipboard or a notepad file. You will need the address for a later step in the walkthrough. For example, the address might resemble this: https://localhost:<PortNumber>/ShoppingWebApp/Default.aspx

  4. Click Go to Log In. The page Login.aspx opens.

  5. Type your name in the text box and then click Log In. The home page opens.

  6. Click Product 1. The page Product1.aspx opens.

  7. Click Add to Cart. The home page opens.

  8. Click Product 2. The page Product2.aspx opens.

  9. Click Add to Cart. The home page opens.

  10. Click Shopping Cart. The page Cart.aspx opens.

  11. Click Buy. The home page opens.

  12. Click Go to Log Out. The page Logout.aspx opens.

  13. Click Log Out. The home page opens.

  14. Close the Web browser.

Creating the Web Performance Test

Now you are ready to create a Web performance test that lets you to test this application.

To create the Web performance test application

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

    The New Project dialog box appears.

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

  3. Under the list of templates, click Test Project.

  4. In the Name box, type ShoppingWebAppTest.

  5. In the Location box, type the name of the folder where you saved the Web application. For example, type the folder name C:\WebSites\ShoppingWebApp.

  6. Click OK.

    The test project is created.

    Note

    By default, Visual Studio will add a unit test file and a text file that has information about authoring tests. You do not need these files for this walkthrough. Therefore, you can delete them. If you do not delete the files, they will not affect the walkthrough.

  7. On the Test menu, click New Test.

    The Add New Test dialog box appears.

  8. In the Add New Test dialog box, select Web Performance Test, name the test WebTest1.webtest, and click OK.

    A new Web performance test file that is named WebTest1.webtest is added to your project, and the Web Performance Test Recorder opens inside a new instance of Internet Explorer.

  9. 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 starts to display the Web performance test URLs in the Web Performance Test Recorder as it is recording.

  10. Click Go to Log In. The page Login.aspx opens.

  11. Type your name in the text box and then click Log In. The home page opens.

  12. Click Product 1. The page Product1.aspx opens.

  13. Click Add to Cart. The home page opens.

  14. Click Product 2. The page Product2.aspx opens.

  15. Click Add to Cart. The home page opens.

  16. Click Shopping Cart. The page Cart.aspx opens.

  17. Click Buy. The home page opens.

  18. Click Go to Log Out. The page Logout.aspx opens.

  19. Click Log Out. The home page opens.

  20. Click Stop on the Web Performance Test Recorder to stop recording.

    Internet Explorer will close and you will see the Web performance test in the Web Performance Test Editor as a list of URLs. After you stop recording, you can modify the test.

  21. On the File menu, click Save All.

To run the Web performance test application

  1. In the Web Performance Test Editor, click Run Test on the toolbar.

    The test starts to run, and a Web Performance Test Results Viewer displays each request in the test. A Test Results window displays the result for the entire test.

  2. In the Test Results window verify that the test passed.

  3. In the Web Performance Test Results Viewer select some of the requests in the list and then examine the results that are shown in the Web browser in the lower pane. Verify that the test is running correctly.

Extracting New Web Performance Tests

You can create new Web performance tests by extracting individual requests from an existing Web performance test. For more information, see How to: Extract Requests in a Web Performance Test to Create a New Web Performance Test.

To extract new Web performance tests from an existing Web performance test

  1. Open WebTest1 in the Web Performance Test Editor.

  2. In the request tree, right-click WebTest1 and then click Extract Web Test.

    The Extract Web Test dialog box appears.

  3. In Web test name type Login.

  4. In the Choose first item for the Web test drop-down select the first request. The request should resemble the following:

    https://localhost:<PortNumber>/ShoppingWebApp/Default.aspx

  5. In the Choose last item for the Web test drop-down list select the third request. The request should resemble the following:

    https://localhost:<PortNumber>/ShoppingWebApp/Login.aspx

  6. Click OK.

    A new Web performance test named Login is created. In the Web Performance Test Editor, Login is added to the request tree in place of the individual requests that you extracted. In Solution Explorer, Login.webtest is added to the project list.

  7. In the request tree, right-click WebTest1 and then click Extract Web Test.

    The Extract Web Test dialog box appears.

  8. In Web test name type BrowseAndBuy.

  9. In the Choose first item for the Web test drop-down select the first request after Login. The request should resemble the following:

    https://localhost:<PortNumber>/ShoppingWebApp/Default.aspx

  10. In the Choose last item for the Web test list select the sixth request. The request should resemble the following:

    https://localhost:<PortNumber>/ShoppingWebApp/Cart.aspx

  11. Click OK.

    A new Web performance test named BrowseAndBuy is created. In the Web Performance Test Editor BrowseAndBuy is added to the request tree in place of the individual requests that you extracted. In Solution Explorer, BrowseAndBuy.webtest is added to the project list.

  12. In the request tree, right-click WebTest1 and then click Extract Web Test.

    The Extract Web Test dialog box appears.

  13. In Web test name type Logout.

  14. In the Choose first item for the Web test list select the first request after BrowseAndBuy. The request should resemble the following:

    https://localhost:<PortNumber>/ShoppingWebApp/Default.aspx

  15. In the Choose last item for the Web test list select the last request. The request should resemble the following:

    https://localhost:<PortNumber>/ShoppingWebApp/Logout.aspx

  16. Click OK.

    A new Web performance test named Logout is created. In the Web Performance Test Editor Logout is added to the request tree in place of the individual requests that you extracted. In Solution Explorer, Logout.webtest is added to the project list.

  17. Confirm that there are no individual requests remaining in the Web performance test request tree. That is, WebTest1 now consists completely of calls to other Web performance tests.

  18. On the File menu, click Save All.

To run the Web performance test application

  1. In the Web Performance Test Editor, click Run Test on the toolbar.

    The test starts to run, and a Web Performance Test Results Viewer displays each request in the test. A Test Results window displays the result for the entire test.

  2. In the Test Results window verify that the test passed.

  3. In the Web Performance Test Results Viewer select some of the requests in the list and then examine the results that are shown in the Web browser in the lower pane. Verify that the test is running correctly.

    Note

    In Web Performance Test Results Viewer there are now collapsible nodes named WebTest1.Login, WebTest1.BrowseAndBuy, and WebTest1.Logout in the tree. This helps you review the parts of your test more easily.

Composing New Web Performance Tests

You can create a new Web performance test by composing existing Web performance tests. For more information, see How to: Insert a Call in a Web Performance Test to Another Web Performance Test.

To compose a new Web performance test from existing Web performance tests

  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 Performance Test, name the test AllTest.webtest, and click OK.

    A new Web performance test file that is named AllTest.webtest is added to your project, and the Web Performance Test Recorder opens inside a new instance of Internet Explorer.

  3. Click Stop on the Web Performance Test Recorder to stop recording without browsing.

    Internet Explorer will close and you will see the Web performance test in the Web Performance Test Editor. The test is empty because you did not browse.

  4. In the request tree, right-click AllTest and then click Add Call to Web Test.

    The Choose Test dialog box appears.

  5. Click Login and then click OK. The Login Web performance test is added to the request tree.

  6. In the request tree, right-click AllTest and then click Add Call to Web Test.

    The Choose Test dialog box appears.

  7. Click BrowseAndBuy and then click OK. The BrowseAndBuy Web performance test is added to the request tree.

  8. In the request tree, right-click AllTest and then click Add Call to Web Test.

    The Choose Test dialog box appears.

  9. Click Logout and then click OK. The Logout Web performance test is added to the request tree.

  10. On the File menu, click Save All.

To run the Web performance test application

  1. In the Web Performance Test Editor, click Run Test on the toolbar.

    The test starts to run, and a Web Performance Test Results Viewer displays each request in the test. A Test Results window displays the result for the entire test.

  2. In the Test Results window verify that the test passed.

  3. In the Web Performance Test Results Viewer select some of the requests in the list and then examine the results that are shown in the Web browser in the lower pane. Verify that the test is running correctly.

Next Steps

Now that you have a Web performance test, you can add it to a load test. You can create a load test that performs the Login and Logout steps only one time per virtual user, and tests the BrowseAndBuy step multiple times per virtual user.

See Also

Tasks

How to: Create a New Web Performance Test Using the Web Performance Test Recorder

How to: Edit an Existing Web Performance Test Using the Web Performance Test Editor

Concepts

Running Web Performance Tests

Web Performance Test Walkthroughs