Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUIT (Coded UI Tests) + MVVM -- Do I have to start naming all my controls now?

Basically, with MVVM I have a lot of my controls unnamed because it isn't necessary to give a Name (or x:Name) to controls anymore.

But, looking into coded UI Tests it seems as if I might have to go through and name all my controls again? Or did I just misunderstand what I read and there is a MVVM friendly way of doing CUIT?

like image 202
myermian Avatar asked Feb 20 '12 04:02

myermian


2 Answers

If you want to reliably interact with a control using recorded tests you will need to provide a name or id for the control. Without names your test will rely on the instance property which as you noticed depends on the location of the unnamed control in relation to other unnamed controls.

If your application is very static you can possibly get away with not having names, but moving controls might result in breakage. You will also run into problems with controls that are loaded dynamically because they can cause the instance values to change and your recorded actions may happen on the wrong control.

Don't get me wrong you can write CodedUI tests for applications without control names it will just be a major pain point and recordings will be unreliable.

like image 121
stoj Avatar answered Nov 10 '22 16:11

stoj


You can add automation ids from the System.Windows.Automation.AutomationProperties namespace instead of having to change the id of the controls. I'd recommend that over expecting the elements to stay in the same order as stoj says above, it would be very painful.

See a post I found on [using the automation id].1 Here are examples from his post:

<MyControl AutomationProperties.AutomationId="AnUniqueValue"/>
protected override string GetAutomationIdCore() 
{ 
    return (AutomationProperties.GetAutomationId(_owner));
}
like image 22
AlignedDev Avatar answered Nov 10 '22 17:11

AlignedDev