Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / C#

Coded UI Test – Tip 4 – Add Unused Controls to UI Map

Rate me:
Please Sign up or sign in to vote.
4.76/5 (7 votes)
8 Aug 2010Ms-PL 42.5K   8   4
How to add unused controls to a UI Map

If you are using coded UI for advanced tests or even a simple test but with complex logic, you might have faced the following dilemma:

How can I add a control inside the UI Map without recording or assertion that control?

Why? Here is a simple scenario:

I’ve created a simple Coded UI Test that opens Calculator (again) and performs a couple of clicks and stops.

Now, I don’t want to add assertion! I just want to use that control for internal logic – I want to replay the test until the sum is over 100 -> How???

Now I’ve dragged the Assertions marker on a new control (Results window), as you can see from the picture below, there are two new objects under the CalculatorWindow tree.

image

This is not enough. In order to add that control inside the UI Map, you need to click on the “Add Control to UI Control Map” button (Alt +C).

And then click "Generate Code” to actually add the control to the UI Map.

image

Now from the code point of view, you can see the UIItem12Text exists and is available for becoming part of my Test Logic.

C#
[TestMethod]
public void CodedUITestMethod1()
{
   this.UIMap.OpenCalc();
           
   double sum = 0;
   while (sum < 100)
   { 
       this.UIMap.Actions();
       sum = Convert.ToDouble
	(this.UIMap.UICalculatorWindow.UIItem12Window.UIItem12Text.DisplayText);
   }
}

Enjoy!

Image 3Image 4

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect Sela
Israel Israel
Shai Raiten is VS ALM MVP, currently working for Sela Group as a ALM senior consultant and trainer specializes in Microsoft technologies especially Team System and .NET technology. He is currently consulting in various enterprises in Israel, planning and analysis Load and performance problems using Team System, building Team System customizations and adjusts ALM processes for enterprises. Shai is known as one of the top Team System experts in Israel. He conducts lectures and workshops for developers\QA and enterprises who want to specialize in Team System.

My Blog: http://blogs.microsoft.co.il/blogs/shair/

Comments and Discussions

 
GeneralMy vote of 1 Pin
Member 109352719-Jul-14 4:27
Member 109352719-Jul-14 4:27 
QuestionCan I load all controls in one shot for coded UI? Pin
vinod chattergee8-Jul-14 20:12
vinod chattergee8-Jul-14 20:12 
GeneralOpenCalc and Actions methods in Coded UI Pin
Madhavi Gadhiraju8-Dec-10 1:37
Madhavi Gadhiraju8-Dec-10 1:37 
GeneralRe: OpenCalc and Actions methods in Coded UI Pin
AbhilashC18-Jan-11 2:30
AbhilashC18-Jan-11 2:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.