Last updated: Jun 11, 2019 12:34
By Dan Maor
Sometimes, you may encounter scenarios in which the desired objects you require for automating your application are not being exposed. More often than not, the issue lies with accessibility information not being correctly defined in the app’s code.
It should be noted that this issue does not stem from a Perfecto bug as it will affect other use cases, such as:
- Automating with other automation tools which are based on Apple’s automation frameworks (XCTest and UIAutomation).
- Turning on VoiceOver on the device and attempting to interact with the objects).
- Using XCode’s Accessibility Inspector.
See the following Sample XCode project (contains compiled samples as well):
The project is comprised of a single ViewController, containing a UICollectionView which is being populated by 30 custom UICollectionViewCell (called PerfectoCollectionViewCell) objects on runtime.
You may attempt to build the project and install it on a device, or use the compiled sample called “AccessibilitySampleDisabled.ipa”. After launching the app, open the Object Spy wizard; as you can see, while the cell labels are being recognized, the cell image is not.
A proposed solution for the issue with this app: in the ViewController implementation file (ViewController.m), observe the cellForItemAtIndexPath method which contains a possible solution for exposing the missing image objects by explicitly enabling accessibility for it and assigning it with an accessibility label. See the method below:
These lines are commented out in the XCode project; you may un-comment them, re-build and install the app or use the attached compiled sample called “AccessibilitySampleEnabled.ipa”. After launching the app, open the Object Spy wizard; as you can see, while the cell labels are now being properly recognized.
The following articles in Apple’s Documentation portal elaborate on the uses and implementation of accessibility in your application: