Search code examples
iosinstrumentsui-automationios-ui-automation

iOS/UI Automation: UIAActionSheet does not have possibilities to manipulate with buttons


My question is related to UI Automation template from XCode's Instruments tool. How does UI Automation support UIActionSheet testing? I know that there is a UIAActionSheet element and I was able to obtain it in my application. But I do not know how to get and manipulate with buttons from the action sheet. UI Automation does not provide any elements for these buttons. The UI Automation documentation does not have any info on the matter either. See the link below. It looks like this control does not use UIButton class for the buttons and renders them in some specific way. Could you give me some clue how to reach the buttons from UIAActionSheet? Thank you.

http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Reference/UIAActionSheetClassReference/UIAActionSheet/UIAActionSheet.html#//apple_ref/doc/uid/TP40009895


Solution

  • As you can see there is method to return default button for each action sheet, which is Cancel button. As there is no other 'default' buttons for action sheet you need to implement those on your own.
    One thing to notice woorth apple reference is that it skips methods for given class which are inherited from parent. UIAActionSheet (like most UIA elements) inherits all methods from UIAElement class. Check this reference. You should be able to get array of all buttons from actionsheet by calling

    var arrButtons = objActionSheet.buttons();
    

    Then you can check by name property which one you need (again method from UIAElement name() ).

    Alliteratively, if you check which element in array you are interested in you could call that button directly (assuming, that you won't change ActionSheet) by using UIAElement method elements().
    For example if you want to tap second button in ActionSheet tree, you just call

    UIATarget.localTarget().frontMostApp().actionSheet().elements()[1].tap();
    

    Maybe you can skip localTarget(), not sure, but code above should work.