Walkthrough: Creating a Web 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 test to test the application.
In this walkthrough, you will perform the following tasks:
Create a simple Web application.
Create a Web test.
Extract new Web tests from an existing Web test.
Compose a new Web test from existing Web tests.
Prerequisites
For this walkthrough you will need:
Microsoft Visual Studio 2005
Visual Studio Team System Test Edition
Creating the Web Application
To create the Web application
In Microsoft Visual Studio 2005, on the File menu, click New and then click Web Site.
The New Web Site dialog box appears.
Under Visual Studio installed templates, click ASP.NET Web Site.
In the Location box, select File System, and then type the name of the folder where you want to keep the Web application. Make the end of the folder name ShoppingWebApp\ShoppingWebApp. For example, type the folder name C:\WebSites\ShoppingWebApp\ShoppingWebApp.
Note
Include the name two times so that you can add a Web test project to the first folder, and it will be separated from the Web application itself in the second folder.
In the Language list, select the programming language you prefer.
Note
You will write minimal code in this walkthrough.
Click OK.
On the File menu, click Save All.
To create the home page for the Web application
In Solution Explorer, right-click Default.aspx and click View Designer.
A blank page is displayed.
If the toolbox is not visible, click View and then click Toolbox.
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")
On the File menu, click Save All.
To add pages to the Web application
On the Website menu, click Add New Item.
In the Add New Item dialog box, click the Web Form template, name it Login.aspx, and then click Add.
At the bottom of the document window, click the Design tab to switch to design view.
Drag a button onto the page.
Drag a text box onto the page.
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.
On the File menu, click Save All.
To test the Web application manually
In Solution Explorer, right-click Default.aspx and then click Set As Start Page.
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 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 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
Click Go to Log In. The page Login.aspx opens.
Type your name in the text box and then click Log In. The home page opens.
Click Product 1. The page Product1.aspx opens.
Click Add to Cart. The home page opens.
Click Product 2. The page Product2.aspx opens.
Click Add to Cart. The home page opens.
Click Shopping Cart. The page Cart.aspx opens.
Click Buy. The home page opens.
Click Go to Log Out. The page Logout.aspx opens.
Click Log Out. The home page opens.
Close the Web browser.
Creating the Web Test
Now you are ready to create a Web test that enables you to test this application.
To create the Web test application
In a new instance of Test Edition, 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.
Under Visual Studio installed templates, click Test Project.
In the Name box, type ShoppingWebAppTest.
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.
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.
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 WebTest1.webtest, and click OK.
A new Web test file that is named WebTest1.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.
Note
Visual Studio starts to display the Web test URLs in the Web Test Recorder as it is recording.
Click Go to Log In. The page Login.aspx opens.
Type your name in the text box and then click Log In. The home page opens.
Click Product 1. The page Product1.aspx opens.
Click Add to Cart. The home page opens.
Click Product 2. The page Product2.aspx opens.
Click Add to Cart. The home page opens.
Click Shopping Cart. The page Cart.aspx opens.
Click Buy. The home page opens.
Click Go to Log Out. The page Logout.aspx opens.
Click Log Out. The home page opens.
Click Stop on the Web Test Recorder to stop recording.
Internet Explorer will close and you will see the Web test in the Web Test Editor as a list of URLs. After you stop recording, you can modify the test.
On the File menu, click Save All.
To run the Web test application
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.
In the Test Results window verify that the test passed.
In the Web Test 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 Tests
You can create new Web tests by extracting individual requests from an existing Web test. For more information, see How to: Extract a Web Test.
To extract new Web tests from an existing Web test
Open WebTest1 in the Web Test Editor.
In the request tree, right-click WebTest1 and then click Extract Web Test.
The Extract Web Test dialog box appears.
In Web test name type Login.
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
In the Choose last item for the Web test drop-down select the third request. The request should resemble the following:
https://localhost:<PortNumber>/ShoppingWebApp/Login.aspx
Click OK.
A new Web test is created named Login. In the Web 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.
In the request tree, right-click WebTest1 and then click Extract Web Test.
The Extract Web Test dialog box appears.
In Web test name type BrowseAndBuy.
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
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
Click OK.
A new Web test named BrowseAndBuy is created. In the Web 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.
In the request tree, right-click WebTest1 and then click Extract Web Test.
The Extract Web Test dialog box appears.
In Web test name type Logout.
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
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
Click OK.
A new Web test is created named Logout. In the Web 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.
Confirm that there are no individual requests remaining in the Web test request tree. That is, WebTest1 now consists completely of calls to other Web tests.
On the File menu, click Save All.
To run the Web test application
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.
In the Test Results window verify that the test passed.
In the Web Test 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 Test 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 Tests
You can create a new Web test by composing existing Web tests. For more information, see How to: Insert a Call to Another Web Test.
To compose a new Web test from existing Web tests
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 AllTest.webtest, and click OK.
A new Web test file that is named AllTest.webtest is added to your project, and the Web Test Recorder opens inside a new instance of Internet Explorer.
Click Stop on the Web Test Recorder to stop recording without browsing.
Internet Explorer will close and you will see the Web test in the Web Test Editor. The test is empty because you did not browse.
In the request tree, right-click AllTest and then click Add Call to Web Test.
The Choose Test dialog box appears.
Click Login and then click OK. The Login Web test is added to the request tree.
In the request tree, right-click AllTest and then click Add Call to Web Test.
The Choose Test dialog box appears.
Click BrowseAndBuy and then click OK. The BrowseAndBuy Web test is added to the request tree.
In the request tree, right-click AllTest and then click Add Call to Web Test.
The Choose Test dialog box appears.
Click Logout and then click OK. The Logout Web test is added to the request tree.
On the File menu, click Save All.
To run the Web test application
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.
In the Test Results window verify that the test passed.
In the Web Test 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 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: Edit an Existing Web Test
Concepts
Running and Viewing a Web Test