I have started writing UI automation tests for IOS using XCUITest. I am a bit confused about setting identifiers to access elements while writing UI tests. Look at the picture.
We have user Defined RunTime Attributes where you can define the key "accessibilityLabel", type as string and value as example "ButtonID". Now, you could use "ButtonID" as the identifier to access the button to write tests.
The second thing I noticed is the Accessibility section where we have a field by name identifier where you could set an identifier and use that identifier to access the UI element.
Could you confirm the difference between the two. Which one of the above two is recommended to set identifiers for UI test.
The effect is the same, by the time your control awakes from nib you'll have your accessibilityIdentifier
/Label
/etc
set up.
Not sure if one way is "officially" preferred over another but I'd recommend using Accessibility section at least for the following reasons:
setValue:forKey:
):* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x000000010efe09fb AccessibilityProbe`-[MyButton setAccessibilityIdentifier:](self=0x00007fbb765231d0, _cmd="setAccessibilityIdentifier:", accessibilityIdentifier=@"testID") at MyButton.m:14
frame #1: 0x0000000112e35538 UIKitCore`-[UIRuntimeAccessibilityConfiguration applyConfiguration] + 153
frame #2: 0x0000000110825cfd CoreFoundation`-[NSArray makeObjectsPerformSelector:] + 317
frame #3: 0x0000000112e33258 UIKitCore`-[UINib instantiateWithOwner:options:] + 1717
¹ Again, implementation details are not something to rely on.