Enter the characters shown in the image.

You are here

Creating Your Automation Solution with CodedUI

Whether you create a project from scratch or use an existing template, you need to add your project to source control for version management and change tracking. To create a new project using Visual Studio, in the New Project dialog box, just select Test and make sure that the Add to Source Control check box is checked.

Here are some recommendations that can help when you're using Team Foundation Server (TFS) for automation source control:

  • For the project check-in path, all application-specific and project-specific automation code should be maintained under the respective project node of the TFS being used for the projects.
  • The recommended source control path can be something similar to <Project-Node>/Main/Test/Test Automation or can follow your TFS folder structure.
  • Follow the standard and custom policies the project administrator enforces, such as entering “comment” every time you check in the code and checking in the code at the end of every day. 

To open an existing test project and use it as a template, launch Visual Studio, go to File, open an existing project and browse to the CodedUISampleFramework template, which is available for download with this article. Then add it to source control and change the properties as needed for your new project.

The following folder structure is used for the template project in this example:

  • Config: Includes all the application configuration details and playback settings, as shown here:
<?xml version="1.0" encoding="utf-8" ?>
    <add key ="URL" value=""/>
    <add key="Test" value="Test Value"/>
  • Library: All the libraries, including application level, data access, exceptions and utilities, go here.
  • Resources: All the keys/strings (e.g., SearchTimeOut, WaitForReadyTimeOut settings and so on) that need to be globally defined can be added here, rather than hard-coding their values. The resource file key SearchTimeOut is used here to set playback settings rather than hard-coding each setting:
/// <summary>
/// Set the SearchTimeOut Playback Option
/// <summary>
public static void SetThinkSearchTimeOut()
    Playback.PlaybackSettings.SearchTimeOut = 
  • Scripts:  Store the test and components such as Test Initialize and Test Cleanup in these .cs files.
  • Test Data: Contains the .CSV or .XML test data files for the data-driven automation test.
  • UI Maps: Contains the test object repository along with any test methods or assertions.
  • Main Class file: One class that acts as a single point interface to all the test methods and contains instantiations of the UI maps.


Designing and Developing Your Automation Framework

The most important phase of automation lifecycle development involves designing the automation framework. If you don’t spend time up front to come up with a good design, you’ll face a lot of rework later. Even if you're eager to start scripting, don't skimp on this phase. You need to spend a good deal of effort in coming up with a design/framework that suits your project requirements before your write your automation tests. This design/framework then serves as a guiding light for team members to follow a standard and consistent automation approach.

This section goes over the automation framework design for coded UI projects using the CodedUISampleFramework template project. Figure 7 illustrates the proposed architecture, which is designed in three tiers for maintaining automated testing that promotes high modularity and maximum reuse with minimum maintenance effort in the longer run.

Proposed three-tier automation architecture

Follow the steps in the following paragraphs to design your automation framework.

If you have created a project from scratch, add multiple UI Map files. In the template project, there are already two UI Map files. For managing object repositories, there are two scenarios: a single UI Map file and multiple UI Map files. By default, only one UI Map file is created per project, which is appropriate for a small project.

For large applications, using multiple UI Map files is recommended. Using multiple UI Map files can provide the following benefits:

  • Each map can be associated with a logical subset of the application, making changes easier to manage.
  • Each tester can work on a section of the application and check in the 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. For information on testing a large application with multiple UI Map files, refer to

After you add a UIMap file, the Visual Studio window minimizes and the Coded UI Test Builder dialog box is displayed, which can be used to record steps or add specific object properties to your UI Map file.

Open the UI Map .cs files to add user-friendly names to the constructor, as shown here:

#region Constructor
public HomepageUI()
    searchText = BingBrowser.BingHomepage.SearchEdit;
    searchSubmit = BingBrowser.BingHomepage.SearchButton;

Now go to the Main Class file (Bing.cs in the example) and instantiate each multi UI Map file, as shown in Figure 8.


Figure 8 Instantiating each multi UI Map file

namespace CodedUISampleFramework
    public class BING
        private static HomepageUI homepageUI;
        private static SearchResultsUI searchResultsUI;
        public static HomepageUI HomepageUI
                if (homepageUI == null)
                    return new HomepageUI();
                return homepageUI;
            set { BING.homepageUI = value; }
        public static SearchResultsUI SearchResultsUI
                if (searchResultsUI == null)
                    return new SearchResultsUI();
                return searchResultsUI;
            set { BING.searchResultsUI = value; }

The UI Test Editor is a handy new feature in Feature Pack 2 that makes it easier to manage your object repository. 

Next you need to add libraries to your project or create and add them if necessary. You need to manage two library types: application functional libraries using multiple UI Map files, and common library and helper classes. For the example in this article, the libraries for Bing are already created.

For application functional libraries using multiple UI Map files, you must ensure that common functionalities you identify in the planning phase are automated as reusable methods. These methods are then invoked from your coded UI test methods. You create functional libraries the same as you would functional modules for your application.

For common libraries and helper classes, first ensure that common operations related to database connections, Excel data access (read/write), XML parsing and string/date manipulations are referenced from the common library repository and shared across the projects. Don't rewrite them from scratch for every project.

All common libraries need to be browsed and added to the automation solution as References through the Add Reference dialog box.

Now you need to ensure that any common helper classes that are technology specific (e.g., Windows Presentation Foundation, Windows Communication Foundation, SharePoint, Silverlight or .NET Framework) are referenced in your solution.

All common code and libraries need to be maintained at a centralized node that is accessible (read-only) to all the projects and applications included for reusability. Only the automation group member has add/edit permission on this node to control the change.

The libaries created for and referenced in the example in this article are shown in Figure 9. The libraries are based on the shared steps and scenarios identified in the automation planning process.

Libraries referenced in the article&#039;s example

The code in Figure 10 shows an example of the application-specific library methods used in the solution.

Figure 10 Application-specific library methods

/// <summary>
/// Enter the search text in Search Edit
/// </summary>
/// <param name="searchText">The text to be Searched in Bing</param>
public static void EnterSearchText(string searchText)
    BING.HomepageUI.searchText.Text = searchText;
/// <summary>
/// Click on the Search Submit button
/// </summary>
public static void SubmitSearch()

Figure 11 is an example of common and utilities-based methods.

Figure 11 Common and utilities-based methods

/// <summary>
/// Navigate to specified URL
/// </summary>
/// <param name="urlString">The url to navigate</param>
public static void Navigate(string urlString)
    browser.NavigateToUrl(new System.Uri(urlString));
/// <summary>
/// Launch and Navigate to specified URL
/// </summary>
/// <param name="urlString">Teh url to navigate</param>
public static void LaunchAndNavigate(string urlString)

The next step is to add the coded UI scripts and test methods to your project. You automate your automatable test cases as coded UI test methods using the application libraries, utilities and UI Maps defined earlier.

First, set the test context, which provides information about and functionality for the current test run:

private static TestContext bingTestContext;
public static TestContext BingTestContext
    get { return BingScriptsBase.bingTestContext; }
    set { BingScriptsBase.bingTestContext = value;}

Second, perform a test initialize. Use the following code before running each test, for tasks such as instantiating UI Map files, setting TestContext for logging and the like.

#region TestInitialize
//Use TestInitialize to run code before running each test

public virtual void MyTestInitialize()
    BING.HomepageUI = new HomepageUI();
    BING.SearchResultsUI = new SearchResultsUI();
    BingTestContext = testContextInstance;

Third, add your Test Methods, as shown in Figure 12.

 Figure 12 Adding test methods

public void SearchText()
   BingScriptsBase.BingTestContext.WriteLine("Test Start");
   Homepage.EnterSearchText("Bill Gates"); //Not recommended to Hardcode values in scripts    
   //Not recommended to use Static Wait Statements as given below 
   //Not recommended to Hardcode values in scripts 
      "Text", "Bill Gates", 15000);
   BingScriptsBase.BingTestContext.WriteLine("Test Stop");

Certain elements are not recommended, such as using a static playback interval or hard-coding test data. In the next section you'll find out how to handle these instances.

Finally, you need to perform test cleanup. Run code similar to the following after each step.

#region TestCleanup
//Use TestCleanup to run code after each test has run

public virtual void MyTestCleanup()
    BING.HomepageUI = new HomepageUI();
    BING.SearchResultsUI = new SearchResultsUI();

Now it’s time to add assertions and checkpoints. For validation in coded UI testing, you need to use Assertions. There are two ways to create assertions: using Coded UI Test Recorder (CUIT) or coding.

Obviously, creating assertions with CUIT is faster than coding them by hand. CUIT, shown in Figure 13, comes in the box with coded UI. It’s simple to use: Just add the comparator and comparison value you want to use and click OK.

Coded UI Test Recorder

You can also create assertions by writing your own code and capturing properties against expected values to validate at run time. Here’s an example:

Verify.WaitForControlPropertyEqual(BING.SearchResultsUI.searchText, "Text", "Bill Gates", 15000);

Here a Verify method in the utility waits for the control property to be equal to some text value for a certain period of time, returning PASS if found or FAIL if not.

public static void WaitForControlPropertyEqual(UITestControl control, 
    string property, string expectedValue, int millisecondsTimeout)
        expectedValue, millisecondsTimeout),
        string.Format("Expected : {0} Actual : {1}", 
        expectedValue, control.GetProperty(property)));

Next you must ensure that every variable is parameterized by passing the test data to each test, using the data-driven capabilities of Visual Studio 2010. As shown in Figure 14, you can right-click the coded UI test and select Properties to view the test’s properties.

View your test properties

To make this a data-driven test, you first have to create a data source for the test to draw from. On the Data Connection String property, click the ellipses button to start the New Test Data Source Wizard.

As shown in Figure 15, there are three options for creating a data source:

  • Database allows you to connect to a database or an Excel spreadsheet.
  • CSV File allows you to use a comma-delimited file.
  • XML File allows you to use an XML file.

Options for creating a data source

When you add a data source, a Data Source attribute is added to the coded UI Test, as follows:

Let’s look at one of the data-driven tests from the example in this article. Here is a method in the data access library (Utilities) to read the data from data sources using the test context:

namespace CodedUISampleFramework.Library
    public class Data
        public static string GetValue(string columnName)
            return (string)BingScriptsBase.BingTestContext.DataRow;

Another method that is part of the application library returns the data from the data source and inputs the same to the application, using the above data access library method:

/// <summary>
/// This method enters Search Text and executes iteratively on the available values
/// </summary>
/// <param name="searchText">The current text used for search</param>
public static void EnterSearchText(out string searchText)
    searchText = Data.GetValue("SearchText");
    BING.HomepageUI.searchText.Text = searchText;       

Next, as shown in Figure 16, the data source, which is stored in .CSV format, is tested.

Testing the data source

Finally, the data-driven test method in Figure 17 shows the code to consume the data source defined earlier.

Figure 17 Sample data-driven test method

#region Scripts

public void SearchTextMany()
    string searchText = null;
    Homepage.EnterSearchText(out searchText);

Once your automation test candidates are designed and developed and your scripts are written and debugged, you need to run them in a batch or as part of a suite. There are various way to do this and factors to keep in mind, as you’ll see in next section.



Testing tool manufacturers world-wide list
10Levels ABID CONSULTING AccelQ Accord Software ActiMind AdaCore
AdaLog AgileLoad AgileWay Agitar Algorismi ALL4TEC
Andreas Kleffel Android Apache Apica Apollo Systems
Applitools AppPerfect Appsee ApTest Assertible Assure
Atlassian AutoIt Consulti .. Automation Anyw .. Automation Cons .. Axosoft Aztaz Software
Backtrace I/O Badboy BlazeMeter Borvid BrowserStack BSQUARE
BStriker Intern .. CA Technologies Canonical Canoo Engineeri .. Catch Software CelestialTeapot
Chris Mallett Cleanscape ClicTest CloudQA Codeborne CodeCentrix
CodePlex projec .. Codoid Cogitek Compuware Configure IT Conflair
ConSol Core Services Coronys Ltd Countersoft CresTech Softwa .. CrossBrowserTes ..
Crosscheck Netw .. Crowdsourced Te .. Cucumber Ltd Cyara Cygnet Infotech DareBoost
Databene Datamatics Glob .. DevExpress DTM soft Dynatrace LLC EasyQA
Eclipse EkaTechserv Elvior Emmanuel Jorge Empirix EPAM Systems
Equafy Esterel Technol .. eXept Software .. Experitest Finaris Froglogic
FrontEndART Ltd GeneXus GitHub project gnoso Google Code Pro .. GrammaTech
Gurock Software HelpSystems HENIX Hewlett Packard .. Hexawise High-Tech Bridg ..
Hiptest Hitex IBM Rational imbus Shanghai Impetus Inflectra
informUp InTENSO - IT Ex .. Ipswitch Jamo Solutions Janova JAR Technologie ..
JBoss Developer jClarity JetBrains Jively jQuery foundati ..
JS Foundation Jspresso Kanoah KMS Technology Kualitee LDRA Limited
Litmus LoadFocus Loadster Perfor .. MarathonITE Marketcircle Marketcircle
Maveryx Meliora Ltd Micro Focus Sof .. Microsoft Mobile Labs Mobile1st
Mockaroo, LLC Monkop Mozila MSys Technologi .. Navicat NeoTys
Neowise Softwar .. NetCart NORIZZK.COM Novosync Mobili .. NRG Global NTT Resonant
OC Systems Odin Technology OpCord Oracle Orcanos Original Softwa ..
OW2 PANAYA Parasoft PassMark Patterson Consu .. Perfecto Mobile
Pivotal, Inc. Plutora Postman (API To .. PractiTest PrimaTest Process One
Programming Res .. Psoda PureLoad PushToTest Python Q-Assurance
QA Systems QACube QASymphony QAWorks QMetry Quali
Qualitia Softwa .. Quality First S .. Quotium RadView Softwar .. Ranorex RedLine13
Reflective Solu .. ReQtest RevDeBug Robotium Tech Rogue Wave Soft .. Rommana Softwar ..
RTTS Runscope Sandklef GNU La .. Sauce Labs Seapine Softwar ..
SeleniumHQ Sencha Sensiple Siemens PLM Sof .. SmartBear Softw .. SmarteSoft
SOASTA SoftLogica Softomotive Softsmith Solution-Soft SonarSource
Sourceforge Spirent Technol .. SQS Software Qu .. Square Stimulus Techno .. Swifting AB
Synopsys T-komp T-Plan TechExcel TechTalk Telerik By Prog ..
Tellurium Test Collab Test Goat Test Recon TestCaseLab Gm ..
TestCraft Techn .. Testenium TestingBot TestLodge Testmunk
Testomato TestOptimal TestPlant TestPro Testsigma Techn .. Testuff
The Core Bankin .. The MathWorks The Open Group Thoughtbot Thoughtworks Time Simulator Top-Q Trace Technolog .. TrendIC TRICENTIS
Tritusa Pty Ltd TWD Solutions P .. TypeMock Tyto Software Ubertesters UniTESK
Universal Test .. Usetrace Ltd Utrecht Univers .. Validata Group Vanamco AG Vector Software
Veracode Verifaya Corpor .. Verit VersionOne Vornex Inc. WcfStorm Soluti .. We Are Mammoth Web Performance .. Wintask Wireshark Found ..
Worksoft Xceptance XK72 Xpand IT XQual ZAPTEST
Zeenyx Software .. Zephyr Zeta Software zutubi pty

CodedUI on YouTube

Theme by Danetsoft and Danang Probo Sayekti