Using Coded UI Tests in Load Tests
This topic applies to:
Visual Studio Ultimate
Visual Studio Premium
Visual Studio Professional
Visual Studio Express
To determine how well your software responds to various levels of usage, you conduct load tests. A load test models the expected usage of a software program by simulating multiple users who access the program at the same time. For more information, see Creating and Editing Load Tests.
Load tests primarily consist of a series of Web performance tests or unit tests that operate under multiple simulated users over a period of time. Load tests can also include automated coded UI tests. The inclusion of coded UI tests should only be done under specific circumstances. All the scenarios that use coded UI tests in load tests involve using the coded UI tests as performance tests. This can be useful because coded UI tests let you capture performance at the UI layer. For example, if you have an application that takes 1 second to return data to the client but 8 seconds to render the data in the browser, you cannot capture this type of performance problem by using a Web performance test.
Another scenario for using coded UI tests in a load test is if you have an application that is difficult to script at the protocol layer. In this case, you might consider temporarily driving load using coded UI until you can correctly script the protocol layer.
Implementing Code for Timing Measurements in Coded UI Tests
By default, you will not get accurate timing measurements from a coded UI test that is used in load tests because the calls are asynchronous. You must implement your coded UI tests correctly to obtain accurate timing measurements. This can be accomplished by using the WaitForControlReady method. The following sample code snippets demonstrate this for a login page.
This is a simplified example. A real test would also have to handle timing if the login failed.
To correctly implement a coded UI test used in a load test
Time how long it takes to load the login page.
TestContext.BeginTimer("UI Login Page Load");
This call loads the login page.
Any timing taken in a Web test must use WaitForReady. This will wait until the form is displayed.
UIMap.UIHttpteamtestweb1STORWindow1.UIHttpteamtestweb1STORDocument.UIEmailEdit.WaitForControlReady(); TestContext.EndTimer("UI Login Page Load");
Be sure that the time that you spend filling out the form is not included in the timer. While recording, generate code from the recorder after filling out a form, but before submitting it.
This function fills out the login form.
Time the login operation
TestContext.BeginTimer("UI Login"); UIMap.LoggedIn();
Any timing taken in a Web test must use WaitForReady. This waits until the login confirmation page is displayed.
UIMap.UIHttpteamtestweb1STORWindow.UIHttpteamtestweb1STORDocument.UIWelcomeJamesBondwellPane.WaitForControlReady(); TestContext.EndTimer("UI Login");
Coded UI Test Limitations in Load Tests
Coded UI Tests drive the mouse and keyboard. Therefore, only 1 virtual user can run coded UI tests per agent. The best way to control this is to set up a separate scenario in the load test, and set the user load to 1 user. If you have more than one UI test, configure the test mix as Sequential. For more information, see Creating Additional Scenarios for an Existing Load Test and Editing Test Mix Models to Specify the Probability of a Virtual User Running a Test.
You also need to configure the load agents to run as an interactive process rather than as a service. For more information, see Installing and Configuring Visual Studio Agents and Test and Build Controllers.