CUIT (Coded UI Tests) + MVVM. Should I now name all my controls?

Basically, with MVVM, I have many of my controls without a name, because there is no need to specify a name (or x: name) for the controls anymore.

But, looking at the coded UI tests, it seems like I might have to go through and call all my controls again? Or did I just misunderstand what I was reading, and is there an MVVM method capable of doing CUIT?

+6
source share
3 answers

You can add automation identifiers from the System.Windows.Automation.AutomationProperties namespace instead of changing the identifier of the controls. I would recommend that expecting the elements to remain in the same order as stoj said above would be very painful.

See the post I found on [using Automation ID]. 1 Here are examples from his post:

<MyControl AutomationProperties.AutomationId="AnUniqueValue"/> protected override string GetAutomationIdCore() { return (AutomationProperties.GetAutomationId(_owner)); } 
+3
source

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

If your application is very static, you can get away with missing names, but moving the controls can cause it to crash. You will also encounter problems with controls that load dynamically because they can cause the values ​​of the instance to change, and your recorded actions may occur if the controls are mismanaged.

Don’t get me wrong, you can write CodedUI tests for applications without control names, it will just be a serious point of pain, and the records will be unreliable.

+4
source

Good, therefore, apparently with unnamed control it is very difficult to make changes that do not violate the coded user interfaces. The generated code assigns editable text fields based on the order in which they are written in XAML, which means that if I move the controls around it, it breaks my encoded user interfaces.

I have not fully studied the search criteria, but I assume that it is much more difficult to create a coded user interface with unnamed controls. Ah, well, I think the name / x: the name will be returned.

+1
source

Source: https://habr.com/ru/post/908866/


All Articles