DCSIMG
Coded UI Test – Tip 4 – Add Unused Controls to UI Map - Shai Raiten

Shai Raiten

 Subscribe

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

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

If you are using Coded UI for advanced tests or even a simple test but with complex logic you might 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 create a simple Coded UI Test that opens Calculator (again) and perform couple of click 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 drag the Assertions marker on a new control (Results window), as you can see from the picture below there is 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 available for become part of my Test Logic.

[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.

Comments

Ed Guzikowski said:

Helpful tip, which has saved us some pain. Just wondering if you ran into the issue of testing non-existence? Here is my scenario, based on the logged in user, I need to check if certain menu items or links are present. This proves to be easy within the WatiN framework by using the Find.

Example:

var link = IeInstance.Link(Find.ByText(row.LinkText));

Assert.IsTrue(link.Exists == row.ExpectedResults[resultKey]);

I have a matrix to run these tests based on user profile, just wondering if there is an easy way to perform the same tests in Coded UI.

My assumption is to add all the controls in and customize my own assertions to perform an Exists check.

# October 3, 2010 9:38 PM

shair said:

Hi,

Each and every CUIT object contains couple of methods that will help you to do so: Object.WaitForControlExists and couple more.

Please let me know if you need additional help.

# October 5, 2010 10:54 AM

insurance licensing classes said:

I am curious  what Alvaro will change with this!?

# December 13, 2010 3:05 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: