I have custom UITableViewCell
with some child images and labels. I have made the entire cell as a single accessible element. I have set accessibility ids to all the elements - cell and its subviews, hoping to be able to use it in the XCUITest
s.
Now, I am not able to get the image, say, using XCUIApplication().images["cell_image_acc_id"]
.
What should I do to get these elements? I am a newbie at XC ui testing. Please let me know if there is something basic that I am missing.
Thanks in advance.
If you set up a view as an accessibility element its subviews are not available for VoiceOver users, and as a result not testable. While it is good for accessibility users, it may affect testability.
You can pass an environmental variable or a launch argument for your app while testing. Do not set isAccessibilityElement
in your app code if such variable (or an argument) is set.
https://developer.apple.com/documentation/objectivec/nsobject/1615141-isaccessibilityelement
https://developer.apple.com/documentation/xctest/xcuiapplication/1500477-launcharguments
https://developer.apple.com/documentation/xctest/xcuiapplication/1500427-launchenvironment
How to detect if iOS app is running in UI Testing mode
This way you can still deliver a great experience for VoiceOver users and test your code properly.