How to use Coded UI in Visual Studio to create automated UI tests

To use the Coded UI for automated testing you need to know three things:

  1. You can use the recording function for Visual Studio to do most of the work
  2. You can do it manually but it requires time and patience.
  3. There are some details which you need to be aware of before you can use Coded UI for testing


Automated UI test recording

This is rather straight forward.

To be able to record a test the following must be true:

  • You application but not in debug mode while you are recording your UI test
  • You have to have a physical focus in a C# test file inside a test method where the recording will create a test call created by the recording process.
  • Before you can start recording you must have your application running.


Next open the “Coded UI Test Builder”:


It should look like this:


At this point open your application on the screen. Then press the red recording button to start recording.

After you are done with your application test steps creation you can add assertions to the test. This happens from the circle in the test builder.

When you are done press the blue arrow pointing to the right with lines below it(the last icon in the test builder). This will generate the test code.

After this, you can start your tests from the test explorer.

Manual UI tests creation

Manual testing can be harder and time-consuming but has the advantage of precision. The basic structure goes as:

  • Create a browser object pointing to a web application
  • Start searching for controls based on search and/or filter properties
  • Do something to the control
  • Do an assertion for the test

public void CodedUITestMethod2()

// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
BrowserWindow browser = BrowserWindow.Launch("some your to your web application");
browser.Maximized = true;
UITestControl control = new UITestControl(browser);
control.TechnologyName = "Web";
control.SearchProperties.Add(HtmlHyperlink.PropertyNames.TagName, "A", HtmlHyperlink.PropertyNames.InnerText, "some text", HtmlHyperlink.PropertyNames.ControlType, ControlType.Hyperlink.Name);
control.SearchProperties.Add(HtmlHyperlink.PropertyNames.Href, "some partial URL", PropertyExpressionOperator.Contains);

Assert.AreEqual(true, control.Exists);

UITestControl control2 = new UITestControl(browser);
control2.TechnologyName = "Web";
control2.SearchProperties.Add(HtmlInputButton.PropertyNames.ControlType, ControlType.Button.Name, HtmlHyperlink.PropertyNames.ValueAttribute, "some text", HtmlHyperlink.PropertyNames.Class, "some css class");

Assert.AreEqual(true, control2.Exists);

UITestControl control3 = new UITestControl(browser);
control3.TechnologyName = "Web";
control3.SearchProperties.Add(HtmlHyperlink.PropertyNames.TagName, "input", HtmlEdit.PropertyNames.Name, "some name", HtmlHyperlink.PropertyNames.Id, "some ID");

Assert.AreEqual(true, control3.Exists);
control3.SetProperty(HtmlEdit.PropertyNames.Text, "some text");

UITestControl person = new UITestControl(browser);
person.TechnologyName = "Web";
person.SearchProperties.Add(HtmlCell.PropertyNames.TagName, "td");
person.SearchProperties.Add(HtmlCell.PropertyNames.ValueAttribute, "namefield");
person.SearchProperties.Add(HtmlCell.PropertyNames.InnerText, "some text", PropertyExpressionOperator.Contains);



For more info on the controls and ways of using go here:

Coded UI – Have to know things


To use the Coded UI you need some version of Visual Studio that supports Coded UI. Currently as of this blog post only Visual Studio Enterprise supports it:

Running tests

You can run tests with or without debug mode for the tests. Notice that Coded UI test debugging is different than debugging your application, meaning that you have to run the debugging for test specifically from the text explorer.


To access the test explorer:



You can’t have your application in debug mode when recording automated UI tests (this is true for Web application, not sure for windows applications). What you need to do is to run your application without debugging. For web apps what this does is that normally IIS Express is launched and the app will be running there. If you are running the app on a manual IIS site well then all you need to do is to start the app.



Coded UI requires Internet Explorer unless you configure it otherwise.

You can start a browser from your code using the following code:

BrowserWindow browser = BrowserWindow.Launch(“some URL”);
browser.Maximized = true;


This is a class inside your test project where the automated recorded tests are saved.


NOTICE: If you have the “Coded UI Test Builder” closed you can double click on the UIMap.uitest to get an overview of your recorded tests.


Dynamic controls or URLs

If you have dynamic controls or URLs then you need to remove the dynamic parts from the recorded code. This means that you have to inside the C# code to remove search properties of filter properties that define dynamic data. Notice that you have to make sure that the remaining properties are enough to find your controls or URLs

You can do this from your Coded UI test class by going to the declaration of the test function in the UIMap class:


Or by opening the UIMap.cs file and under it the UIMap.Designer.cs file.


Basically what you are looking for is something like the code example below. The commented out code is in this case, the dynamic data which changes. The code assumes that the rest of the properties will do the job in finding the control:

public HtmlCheckBox UI__listitem___id_5066CheckBox
if ((this.mUI__listitem___id_5066CheckBox == null))
this.mUI__listitem___id_5066CheckBox = new HtmlCheckBox(this);
#region Search Criteria
//this.mUI__listitem___id_5066CheckBox.SearchProperties[HtmlCheckBox.PropertyNames.Id] = "__id_50661";
//this.mUI__listitem___id_5066CheckBox.SearchProperties[HtmlCheckBox.PropertyNames.Name] = "__listitem___id_50660";
this.mUI__listitem___id_5066CheckBox.FilterProperties[HtmlCheckBox.PropertyNames.Value] = "some value";
this.mUI__listitem___id_5066CheckBox.FilterProperties[HtmlCheckBox.PropertyNames.LabeledBy] = null;
this.mUI__listitem___id_5066CheckBox.FilterProperties[HtmlCheckBox.PropertyNames.Title] = null;
this.mUI__listitem___id_5066CheckBox.FilterProperties[HtmlCheckBox.PropertyNames.Class] = "__checkbox";
this.mUI__listitem___id_5066CheckBox.FilterProperties[HtmlCheckBox.PropertyNames.ControlDefinition] = "name=\"__listitem___id_50660\" class=\"__ch";
this.mUI__listitem___id_5066CheckBox.FilterProperties[HtmlCheckBox.PropertyNames.TagInstance] = "27";
this.mUI__listitem___id_5066CheckBox.WindowTitles.Add("Some URL");
return this.mUI__listitem___id_5066CheckBox;

Search and Filter properties when searching for controls – What’s the difference?

The difference is that the search properties act as AND operators. While the filter properties act as OR operators.

Mobile Device Testing and Debugging with VirtualBox, Android Studio, Visual Studio and IIS

This post is from the perspective of a person who has a Microsoft technologies based web solution that needs to connect with a mobile device. This might work for other types of technologies and virtual machines with some or alot of tuning. Basic principles should be more or less the same.

I will give firstly an introduction on the solution used in my scenario:

I have a Android mobile device with an app in it that needs to connect to a webapi service to retrieve data and post data to it. The thing which this post is concerned about, is debugging the app with Android studio using the app from the Android device against a webapi which is also under debug mode in Visual Studio. This way I can see what is happening both on the client and on the server side.

Basically how this works is that you will have to connect with your mobile device to a local network where your physical machine exists. Because you are using a mobile device the logical way is over WiFi and no having your device plugged in to your physical machine by USB does not work. You can not directly connect to a localhost that way. Well atleast I could not make it to work. Notice that you can connect to a localhost from Android Studio while debugging your Android app but this is only possible is your a emulating the app locally. Even then though you might have problems and have to configure your solution in such a way that your app will pick it up.

This post assumes that you have a ready build for your server side solution at a location in your development machine. Here are the steps:

1. Create IIS site

– Add a new application to IIS which points to your solution build location.


– Next make sure that the application pool account has enough privileges to the location. I do this by creating a new account to AD or I create a local machine account on my development machine.

This is to configure the Application Pool account:

These steps are for the file system level:


– If you are using a database in your application make sure that the application pool account has the proper privileges. This depends of course on how you have built your solution.
– Assign a port to your web application



2. Config ports and firewall settings
– Next you need to allow inbound and outbound connections to you web application through the port which was earlier configured for the web application. This needs to be done for both the virtual machine and your actual physical machine.

For virtualBox:

For WMWare:

3. Attach to process

The next steps is to attach your developer tools to your server solution and your mobile application to whatever developer tools your are using, something like Android Studio or XCode.

Config VirtualBox

How to Forward Ports to a Virtual Machine and Use It as a Server


Good To Know: ASP .NET MVC Reference Guide


This is my collection of sources of the most “relevant” information on ASP .NET MVC. Hope this helps you if you need information on MVC and web development with Microsoft Tools.

Design the application architecture – Application Layers, Azure, State Management, Caching, WebSocket, HTTPModules
ASP.NET MVC 4 Content Map
.NET On-Premises/Cloud Hybrid Application Using Service Bus Relay
A Beginner’s Guide to HTTP Cache Headers
ASP.NET MVC Views Overview
ASP.NET Routing
ASP.NET State Management Overview
Beginners guide to HTML5 Application Cache API
Caching in .NET Framework Applications
Controllers and Action Methods in ASP.NET MVC Applications
Differences Between ASMX and WCF Services
Distributed Cache
Donut Caching and Donut Hole Caching with Asp.Net MVC 4
Donut Caching with ASP.NET MVC 4
Entity Framework
Extending ASP.NET Processing with HTTP Modules
Getting Started with ASP.NET Web API 2
Global.asax File
HOW TO: Write a Simple Web Service by Using Visual C# .NET
HTML5 Web Storage
HTTP Handlers and HTTP Modules Overview
IHttpModule Interface
Improving Performance with Output Caching (C#)
INFO: ASP.NET Configuration Overview
Introducing “Razor” – a new view engine for ASP.NET
Introducing WebSocket HTML5
Introducing Windows Azure
Introducing Windows Azure AppFabric Applications
Introduction to HTTP Modules
Learn About ASP.NET Web API
patterns & practices: Data Access Guidance
Run Startup Tasks in Windows Azure
The WebSocket API
Two Ways of Passing HTML5 Web Storage Data to ASP.NET
Use AppCmd.exe to Configure IIS at Startup
Using an Asynchronous Controller in ASP.NET MVC
WCF Web HTTP Programming Model
Windows Azure Execution Models
Windows Azure Jump Start (03): Windows Azure Lifecycle, Part 1
Windows Azure Jump Start (04): Windows Azure Lifecycle, Part 2
Design the user experience – User Interface Design and Implementation
About Font Embedding
AjaxExtensions.BeginForm Method
ASP.NET MVC 4 Content Map
Compatibility tables for support of HTML5, CSS3, SVG and more in desktop and mobile browsers.
CSS Media Types
CSS Reference
DisplayModeProvider Class
EditorExtensions.EditorFor Method
How To Test ModelState.IsValid In ASP.NET MVC
How to: Implement Remote Validation in ASP.NET MVC
How to: Validate Model Data Using DataAnnotations Attributes
HTML DOM innerHTML Property
Html.BeginForm() vs Ajax.BeginForm() in MVC3
HTML5 New Input Types
HtmlHelper Class
JavaScript prototype Property
JavaScript Tutorial
jQuery Documentation
jQuery Mobile
jQuery Mobile Framework
jQuery UI
JsonRequestBehavior Enumeration
JsonResult Class
Kendo UI Mobile
LinkExtensions.ActionLink Method
ModelStateDictionary.IsValid Property
Partial View in ASP.NET MVC 4
Rendering a Form in ASP.NET MVC Using HTML Helpers
Sencha Touch
Simplifying HTML generation in code using Razor templates
Styles.Render Method
System.Web.Mvc.Ajax Namespace
System.Web.Mvc.Html Namespace
Understanding JavaScript Prototypes.
Using the viewport meta tag to control layout on mobile browsers
ValidationExtensions.ValidationMessageFor Method
ValidationMessageFor HTML Helper in MVC3 Razor
Vendor-specific Properties
Views and UI Rendering in ASP.NET MVC Applications
Develop User Experience – Search Engine Optimization, Globalization and Localization, Routes, Application Behaviour, Network Optimization
13 ASP.NET MVC extensibility points you have to know
Action Filtering in ASP.NET MVC Applications
ActionResult Class
ActionResult.ExecuteResult Method
An Introduction to ASP.NET MVC Extensibility
ASP.NET Globalization and Localization
ASP.NET MVC – Basic overview of different view engines
ASP.NET MVC Custom Model Binder
ASP.NET MVC Model Binding and Data Annotation
ASP.NET MVC Routing Overview (C#)
ASP.NET Routing
Attribute Usage Guidelines
BindAttribute Class
Bundling and Minification
Configuring HTTP Compression in IIS 7
CultureInfo Class
Custom Controller Factory in ASP.NET MVC
FilterAttribute Class
HandleErrorAttribute Class
How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization
HTML 5: The Markup Language (ARIA Edition)
Mage.exe (Manifest Generation and Editing Tool)
Microsoft Ajax Content Delivery Network
MVC 4 Part 4 – Bundles and Optimisation
MvcRouteHandler and MvcHandler in ASP.NET MVC Framework
ResourceManager Class
Search Engine Optimization Toolkit
Subscriber Locale Codes
The Features and Foibles of ASP.NET MVC Model Binding
Thread.CurrentUICulture Property
Using CDN for Windows Azure
Using Value Providers in ASP.NET 4.5
Walkthrough: Organizing an ASP.NET MVC Application using Areas
WebPart.AuthorizationFilter Property
What’s the Difference Between a Value Provider and Model Binder?
ViewResultBase Class
VirtualPathProviderViewEngine Class
Troubleshoot and debug web applications – Runtime issues, Exception handling, Testing, Debuging
AppDomain.FirstChanceException Event
Assert Class
Beginners Guide to Performance Profiling
Code Contracts
Code Contracts
Code Contracts for .NET
Collect Logging Data by Using Windows Azure Diagnostics
Configuring Performance Sessions for Profiling Tools
Configuring Windows Azure Diagnostics
Controller.OnException Method
Create and Use Performance Counters in a Windows Azure Application
customErrors Element (ASP.NET Settings Schema)
Debugging a Cloud Service in Visual Studio
Debugging Cloud Services
HandleErrorAttribute Class
How To Put Your Toe Into ASP.NET MVC Integration Testing
How to: Break When an Exception is Thrown
How to: Handle Application-Level Errors
How to: Receive First-Chance Exception Notifications
Integration Testing Your ASP.NET MVC Application
Invariants and Inheritance in Code Contracts
Isolating Code Under Test with Microsoft Fakes
Logging Error Details with ASP.NET Health Monitoring (C#)
MVC: Error Page implementation
Performance and Diagnostics Hub in Visual Studio 2013
Performance Profiler in Visual Studio 2012
Quick Start: Test Driven Development with Test Explorer
Record and run a web performance test
Remote Debugging a Window Azure Web Site with Visual Studio 2013
System.Diagnostics.Contracts Namespace
TraceListener Class
Tracing in ASP.NET MVC Razor Views
Understanding Web Tests
Unit Testing in ASP.NET MVC Applications
Use the Windows Azure Diagnostics Configuration File
Walkthrough: Using TDD with ASP.NET MVC
What is a First Chance Exception?
Windows Performance Monitor
Working with Web Tests
Design And Implement Security – Authentication, Authorization, Data Integrity, Hacks and Security, Communication
A Beginner’s Tutorial on Custom Forms Authentication in ASP.NET MVC Application
A Custom SqlRoleProvider for “Authenticated Users”
Anti-Cross Site Scripting Library
Apple Secure Coding Guide
ASP.NET Impersonation
ASP.NET MVC Authentication – Global Authentication and Allow Anonymous
Asp.Net MVC With the ValidateAntiForgeryToken For Cross Site Request Forgeries
ASP.NET Web Application Security
Authenticating Users with Windows Authentication (C#)
AuthorizeAttribute Class
Basic Security Practices for Web Applications
Client Certificates vs. Server Certificates – What’s the Difference?
Configure ASP.NET Impersonation Authentication (IIS 7)
Create an ASP.NET MVC 5 App with Facebook and Google OAuth2 and OpenID Sign-on (C#)
CryptoStream Class
Custom Authentication and Authorization in ASP.NET MVC
Custom Authentication with MVC 3.0
Custom Membership Providers
Custom Membership Providers – Task Manager
Custom Role Providers
DpapiProtectedConfigurationProvider Class
FormsIdentity Class
How to Authenticate Web Users with Windows Azure Active Directory Access Control
How to configure Custom Membership and Role Provider using ASP.NET MVC4
How to Create an Intranet Site Using ASP.NET MVC
How to: Create a WindowsPrincipal Object
How to: Create GenericPrincipal and GenericIdentity Objects
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA
How To: Use Membership in ASP.NET 2.0
HtmlHelper.AntiForgeryToken Method
HttpEncoder Class
Microsoft Web Protection Library
OAuthWebSecurity.Login Method
OAuthWebSecurity.VerifyAuthentication Method
patterns & practices Improving Web Services Security – Now Released
Programming WCF Security
Provider Model Design Pattern and Specification, Part 1
RequireHttpsAttribute Class
Role-Based Authorization (C#)
RSACryptoServiceProvider Class
RsaProtectedConfigurationProvider Class
SAML 2.0 tokens and WIF – bridging the divide
Securing Your ASP.NET Applications
Security Practices: ASP.NET Security Practices at a Glance
Seed Users and Roles with MVC 4, SimpleMembershipProvider, SimpleRoleProvider, Entity Framework 5 CodeFirst, and Custom User Properties
SqlMembershipProvider Class
SqlRoleProvider Class
System.Security.Cryptography Namespace
System.Threading.Thread.CurrentPrincipal vs. System.Web.HttpContext.Current.User or why FormsAuthentication can be subtle
Thread.CurrentPrincipal Property
Understanding and Using Simple Membership Provider in ASP.NET MVC 4.0
Understanding the Forms Authentication Ticket and Cookie
Understanding Windows Identity Foundation (WIF) 4.5
Using IIS Authentication with ASP.NET Impersonation
Using OAuth Providers with MVC 4
Walkthrough: Using Forms Authentication in ASP.NET MVC
WCF Security Fundamentals
WCF Using Windows Authentication and SqlRoleProvider over basicHttp
WebSecurity Class
Windows Communication Foundation Security
WindowsIdentity Class
WS-Trust 1.3 OASIS Standard

Testing for software developers – Thoughts

Today I had conversation with a few developers and we discussed the issue of testing in situations where there is no dedicated testes or testing manager OR someone who would test what you are doing besides yourself.

What to do?

Well with SharePoint there are lots of different things to test which complicate things. Things like TDD are not necessarily useful with SharePoint or similar environments where you are creating small apps for a ECM or CMS products like SharePoint. It can be useful BUT in my experience it needs more complex application logic to or other lets say external databases that need to be integrated in a clients SharePoint application. Webparts are usually rather small in logic on functionality.

Here is a checklist on how to improve your testing as a developer and minimize the risk of bugs and errors in your application:

  • Categorize your “testing plan” based on functionality in different parts of your application. For Example: Testing a List Event in SharePoint can have certain steps you want to take. These steps are most likely to stay the same next time you do a similar list event.
  • For each your “testing plan” write down what you had to test to ensure that what you where working on performed without problems. These things might even come up as a bug later on while the client tests your new work.

This is a over simplified way of looking at things BUT if you have a checklist for different things you know you are most likely to encounter then every time you work on your code you can go through your checklist and see if you have included into your code similar steps to avoid repeating your errors from the past. Saves time and energy.

I know there are all kinds of “best practices”, terms and procedure etc for testing and quality assurance but this is just meant for a developer for your own personal needs. Especially in situations where there are no quality assurance steps available, no testing or similar possible.

The main point of this article: It is always good to spend a few moment to think how one can use what one has  learned and put it to use later to make your life easier. Less stress more fun :)!