Lightweight Test Automation Framework for ASP.NET
What is the Lightweight Test Automation Framework for ASP.NET?
The Lightweight Test Automation Framework for ASP.NET was developed and is used by the
ASP.NET QA Team
to automate regression tests for the product. It is designed to run within an ASP.NET application.
Tests can be written in any .NET Framework language. They use an API to manipulate and verify the DOM of the browser. This framework supports running tests in Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, and Opera.
Note that even though the Lightweight Test Automation Framework for ASP.NET can be used to automate testing for any general-purpose Web application, its design was driven by the needs of the QA Team to automate ASP.NET regression tests.
What is included in this release?
This release contains two downloads. One download contains the source code and unit tests for the automation framework. It also includes a sample Web site that demonstrates how to use the test framework. The second download contains only the sample Web site.
Use this download if you want only the compiled binaries and do not need the source code and unit tests.
How do I work with the source code?
Download the Lightweight Test Automation Framework solution from the
Lightweight Test Automation Framework Nov. Release
site and then open it in Visual Studio 2008.
The solution contains the following projects:
- Microsoft.Web.Testing.Light. This project contains the source code for the framework.
- Microsoft.Web.Testing.Light.UnitTests. This project contains the unit tests written using MSTest.
- SampleWebSite. This project contains a file-system Web site that contains sample tests.
- FunctionalTestsWebSite. This project contains a file-system Web site that contains Build Verification Tests (BVTs) written using the framework itself.
How do I use the samples?
1. Download the sample from the Web site and then open it in Visual Studio 2008. The Web site contains a small application and tests to automate it. The following illustration shows the Web site structure.
2. Navigate to Home.aspx to interact with the Web site. To log in, use the user name ValidUser and use any string for the password. The page contains a GridView control that lets the user edit, delete, and insert data about school classes and grades. The following
illustration shows a screen shot of the sample application.
3. Navigate to \test\Default.aspx. This loads the testing UI, shown in the following illustration:
4. Select tests from the tree view and then click Run Tests. The tests will run and display their progress in the right-hand frame.
5. To examine the test code, browse to the App_Code\Tests folder, and then open any file to inspect the test source code.
How do I debug test errors?
When a test fails, it is marked in red in the test tree. To examine the log, click the test name. The log information is displayed as shown in the following illustration:
The log contains the stack trace of the test and the DOM that was captured by the Lightweight Test Automation Framework at the moment of failure.
You can also have the test framework write a simple log to disk. To do so, select the Write Log to Disk check box before you run the tests. Note that this feature requires write access to the Web site’s root folder.
How do I use the Lightweight Test Automation Framework for ASP.NET with my own Web site?
To use the test framework in your Web site, follow these steps.
1. Copy Microsoft.Web.Testing.Light.dll into the Bin folder of your Web site. If you are testing a Web application, add the DLL as a reference to the project.
2. Copy Default.aspx and DriverPage.aspx into a folder in the Web site.
By convention, the ASP.NET QA team uses the Test folder, but you can use any folder that you want. These are the pages that are required in order to run the tests. If you are testing a Web site project, put tests in the App_Code folder. If you are testing a
Web application project, you can put tests in any folder.
How do I filter the test tree?
The automation framework accepts the query-string values that are useful for filtering and running tests. You add these arguments when you request a page in the browser in order to start a test.
You can use the following query-string variables:
- Selects all tests that are marked with the WebTestTagAttribute and that have the specified identifier. For example, to have the framework automatically select a method that is marked with the [WebTestTag("DataScenarios")] attribute, you can browse
to the following URL:
- By default, the names of all classes that are marked with the WebTestClassAttribute and the name of all methods that are marked with the WebTestMethodAttribute are already identifiers.
- You can specify multiple tag identifiers by concatenating them with the “@” symbol, as shown in the following example:
- This example shows how to automatically select all tests that have the [WebTestTag("Pri0")] attribute and additionally to select the test method named “MyTestMethod”.
- Passing true causes the Lightweight Test Automation Framework to remove all unselected tests from the test tree.
- Passing true causes the Lightweight Test Automation Framework to start running the selected tests on load.
For more information, see the following resources: