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?
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.
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With