Setting unique ID on iOS UI components in Xamarin

Our test engineers who are using Appium are asking us to set a unique ID on various UIViews within our app in order that they can be targeted during test automation. Note that our app is completely dynamic, hence the need for a custom ID rather than using xpath. Unfortunately, it seems that NONE of the properties accessible by Appium for setting this unique ID are available through the Xamarin API. Under UIView, for example, the only sensible property we could set would be the AccessibilityIdentifier property, but this property is apparently unavailable on the Appium side. What is more peculiar is that our Appium devs have suggested setting the “name” property, but this is not a property of UIView from what we can determine based on Apple’s documentation.

Any suggestions on this would be much appreciated.

On IoS accessiblityIdentifier once set can be accessed in your test code through FindElementByAccessibilityID for automation testing. However, I have yet to find a way to see what this accessibilityIdentifier has been set to using the Appium inspector. The corresponding Android field is content-description and can be succefully seen using the Appium inspector.

Here’s a link I found helpful:
https://saucelabs.com/blog/advanced-locator-strategies

-Tony

normally test engineers have to put ‘accessibilityIdentifier’ labels themselves :slight_smile:

two ways:

  1. in storyboard add “accessibilityIdentifier” to static elements like MAIN view (this will help to detect what storyboard = screen we see on phone) and other elements like some view or buttons.
  2. with some elements that are generated and deeply reusing in code like some cells add some “accessibilityIdentifier” meaningful name (e.g. someCell.accessibilityIdentifier = “personCell”). for elements inside cell you can set in cell UI view similar like in storyboard.

and one note: your “accessibilityIdentifier” will be visible in app structure for testing as “name” attribute. but that should not confuse. to see structure of any screen we need with Appium call: ‘driver.getPageSource()’

This feedback is very helpful guys. Thank you very much.

One more question… Say we have a number of child views which are uniquely named, and each child view has a number of input controls which are also uniquely named within their superview, but not necessarily unique across the other child views, will Appium allow one to target an input control relative to a specific parent view? In other words…

UIView (ID = undefined)
|
|_____UIView (ID = "V1")
|     |______ UIView (ID = "C1")
|     |______ UIView (ID = "C2")
|
|_____UIView (ID = "V2")
      |______ UIView (ID = "C1") <-- I want to target this "C1"
      |______ UIView (ID = "C2")

Keep in mind that I don’t necessarily know how many other parent views who have a child named “C1” are on the display. I also don’t know the position of “V2” as the app is dynamic and may appear before “V1”. All I know is that I’m looking for a child named “C1” under a parent named “V2”.

All is fine. First part is we detecting which screen we have. Then we know what ids should expect on this screen. Many screens can reuse same elements with same ids. Strongly suggest your QA look into Google Page object pattern and use it. Example of code you may find in Appium java-client component test folder.