If you want to automate your user interface for testing or to take screenshots using fastlane you can use Apple’s UI Automation framework. Every element from UIKIt has a corresponding class in UI Automation – every? No, not every element.
The UIStepper class does not has a corresponding UIAStepper class in the testing framework, but it would be nice to automate it, too. If you record your activities on the UI with Instruments you will get something like this:
If you want to create this not using Instruments it becomes tricky. Even if you try to use the accessibility labels you will fail. By the way: The UIStepper does not has accessibility properties in Interface Builder.
So, what’s the solution?
If you look at the array that is returned by calling
elements() on the parent element you will find two
UIAButton entries. One with the name „Increment“ and one with the name „Decrement“ – and these two can be used to automate UIStepper actions!
To simulate a tap on the ‚+‘ button on a UIStepper you can simply write:
to simulate a tap on the ‚-‚ button respectively.
But there is a small snare: The names of the elements are localized! So you have to check for your localization and use the correct strings. For German the strings are ‚Erhöhen‘ and ‚Verringern‘.
It’s that easy, but not documented by Apple. Have fun!