How to: Set Up Your Silverlight Application for Testing
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
You can use coded UI tests to create automated tests for Silverlight 4 applications by using Visual Studio 2010 Ultimate or Visual Studio 2010 Premium. You can also create action recordings for your manual tests for Silverlight 4 applications by using Microsoft Test Manager.
Only Silverlight 4 applications that are hosted in an Internet Explorer window are supported. Silverlight 4 applications that are hosted using a different browser or are not hosted in a browser are not supported.
To set up your Silverlight application to be able to create coded UI tests or action recordings for it, you must perform the following key tasks:
Add Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper.dll as a reference to each Silverlight 4 project in your solution so that the Silverlight controls can be identified.
Verify that each Silverlight control has a unique identification property.
To set this property for different controls, see Set a Unique Automation Property for Silverlight Controls for Testing.
Build the application and deploy it.
The SilverlightUIAutomationHelper.dll cannot be redistributed as part of your application. When you add this DLL to your Silverlight project, you must add it so that you can conditionally compile the application with or without this DLL, as shown in the following procedure. You can create a build with the DLL that will be used for testing only. In in this manner, you will not redistribute the DLL.
The following controls are supported for action recordings and coded UI tests:
The standard controls that are shipped as part of the Microsoft Silverlight 4 Tools for Visual Studio 11 Developer Preview are supported.
Custom controls that are derived from the standard controls in Microsoft Silverlight 4 Tools are supported.
Custom controls that inherit from System.Windows.Controls.Control. Depending on how you customize these controls, there might be limited support for some actions. In addition, it might not be possible to get the values of some properties for validations.
The following controls are not supported for action recordings and coded UI tests:
Custom controls that are not derived from the controls supplied as part of the Microsoft Silverlight 4 Tools for Visual Studio 11 Developer Preview.
Third-party controls might not be supported, depending on how these controls were created.
You can create a custom plugin to support testing of a custom control. For an example about how to create a custom plug in, see Extending Coded UI Tests and Action Recordings to Support Microsoft Excel.
Use the following procedures to add or remove the SilverlightUIAutomationHelper.dll:
Add the SilverlightUIAutomationHelper.dll to a Silverlight 4 project
Remove the SilverlightUIAutomationHelper.dll from a Silverlight 4 project
To set a unique identification property for each Silverlight control, see the following topic: Set a Unique Automation Property for Silverlight Controls for Testing.
To Add the SilverlightUIAutomationHelper.dll to a Silverlight 4 Project
To open the solution that contains any one of your Silverlight projects, click File and point to Open. Click Project/Solution.
The Open Project dialog box is displayed.
Select your solution, and then click Open.
For each Silverlight project in your solution that you want to test, you must add the SilverlightUIAutomationHelper.dll. To add this, right-click the project and then click Unload Project
Right-click the project that you unloaded and then click Edit <project name>.
You will see PropertyGroup nodes followed by ItemGroup nodes.
To set the production condition to use to conditionally add the SilverlightUIAutomationHelper.dll, you must make the following two modifications:
To set the production condition, add the following entry to the first <PropertyGroup> node:
To add the DLL when the build is not a production build, insert the following Choose node after the PropertyGroup nodes, but before the ItemGroup nodes:
<Choose> <When Condition=" '$(Production)'=='False' "> <ItemGroup> <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension.SilverlightUIAutomationHelper"> </Reference> </ItemGroup> </When> </Choose>
To save the file, click Save.
To reload these changes, right-click the project and then click Reload Project
If you have multiple Silverlight projects that you want to test, you must follow these steps for each project.
To Remove the SilverlightUIAutomationHelper.dll from a Silverlight 4 Project
To remove the SilverlightUIAutomationHelper.dll so that it is not redistributed with your production code, set the production condition value to true in the first <PropertyGroup> node:
In this manner, the DLL is no longer added as a reference by the Choose node that you added to the project in the previous procedure.
You can also set an environment variable named Production to the value True. Then you can use msbuild to build the Silverlight project and remove the SilverlightUIAutomationHelper.dll.