Skip to main content

Testing a Large Application with Multiple UI Maps

Requirements
  • Visual Studio Ultimate, Visual Studio Premium
When you create a new coded UI test, the Visual Studio testing framework generates code for the test by default in a UIMap class. 

The generated code for the UI Map contains a class for each object that the test interacts with. For each generated method, a companion class for method parameters is generated specifically for that method. If there are a large number of objects, pages, and forms and controls in your application, the UI Map can grow very large. Also, if several people are working on tests, the application becomes unwieldy with a single large UI Map file.
Using multiple UI Map files can provide the following benefits:
  • Each map can be associated with a logical subset of the application. This makes changes easier to manage.
  • Each tester can work on a section of the application and check in their code without interfering with other testers working on other sections of the application.
  • Additions to the application UI can be scaled incrementally with minimal effect on tests for other parts of the UI.

Adding multiple UIMaps:

To add a UI Map to your coded UI test project

  1. In Solution Explorer, to create a folder in your coded UI test project to store all the UI Maps, right-click the coded UI test project file, point to Add and then choose New Folder. For example, you could name itUIMaps.
    The new folder is displayed under the coded UI test project.
  2. Right-click the UIMaps folder, point to Add, and then choose New Item.
    The Add New Item dialog box is displayed.
    Note Note
    You must be in a coded UI test project to add a new coded UI test map.
  3. Select Coded UI Test Map from the list.
    In the Name box, enter a name for the new UI Map. Use the name of the component or page that the map will represent, for example, HomePageMap.
  4. Choose Add.
    The Visual Studio window minimizes and the Coded UI Test Builder dialog box is displayed.
  5. Record the actions for the first method and choose Generate Code.
  6. After you have recorded all actions and assertions for the first component or page and grouped them into methods, close the Coded UI Test Builder dialog box.
  7. Continue to create UI Maps. Record the actions and assertions, group them into methods for each component, and then generate the code.
In many cases, the top level window of your application remains constant for all wizards, forms, and pages. Although each UI Map has a class for the top level window, all maps are probably referring to the same top level window within which all components of your application run. Coded UI tests search for controls hierarchically from the top down, starting from the top level window, so in a complex application, the real top level window could be duplicated in every UI Map. If the real top level window is duplicated, multiple modifications will result if that window changes. This could cause performance problems when you switch between UI Maps.
To minimize this effect, you can use the CopyFrom() method to ensure that the new top level window in that UI Map is the same as the main top level window.

Example:
The following example is part of a utility class that provides access to each component and their child controls which are represented by the classes generated in the various UI Maps.
For this example, a Web application named Contoso has a Home Page, a Product Page, and a Shopping Cart Page. Each of these pages share a common top level window which is the browser window. There is a UI Map for each page and the utility class has code similar to the following:
using ContosoProject.UIMaps;
using ContosoProject.UIMaps.HomePageClasses;
using ContosoProject.UIMaps.ProductPageClasses;
using ContosoProject.UIMaps.ShoppingCartClasses;

namespace ContosoProject
{
    public class TestRunUtility
    {
        // Private fields for the properties
        private HomePage homePage = null;
        private ProductPage productPage = null;
        private ShoppingCart shoppingCart = null;

        public TestRunUtility()
        {
            homePage = new HomePage();
        }

        // Properties that get each UI Map
        public HomePage HomePage
        {
            get { return homePage; }
            set { homePage = value; }
        }

        // Gets the ProductPage from the ProductPageMap.
        public ProductPage ProductPageObject
        {
            get
            {
                if (productPage == null)
                {
                    // Instantiate a new page from the UI Map classes
                    productPage = new ProductPage();

                    // Since the Product Page and Home Page both use
                    // the same browser page as the top level window,
                    // get the top level window properties from the
                    // Home Page.
                    productPage.UIContosoFinalizeWindow.CopyFrom(
                        HomePage.UIContosoWindowsIWindow);
                }
                return productPage;
            }
        }

    // Continue to create properties for each page, getting the 
    // page object from the corresponding UI Map and copying the 
    // top level window properties from the Home Page.
}

Popular posts from this blog

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.

Resolving 'Setup Account Privileges' error while installing SQL Server

A new installation of Microsoft SQL Server 2012 or Microsoft SQL Server 2008 R2 fails You see the following error message when you try to install a new instance of SQL Server 2012 or SQL Server 2008 R2: Rule "Setup account privileges" failed.

Creating Oracle stored Procedures using TOAD for Oracle

In a database management system, a  stored procedure  is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of  stored procedures  can be helpful in controlling  access to data, preserving  data integrity  and  improving  productivity.