Search code examples
iosuiactivityviewcontrollerxcuitest

XCUITest and UIActivityViewController


How do you access a UIActivityViewController (share / actions sheet) in XCUITest? According to the Accessibility Inspector, t is comprised of several UICollectionViews, which makes it hard to disambiguate the sheet itself.

Querying for XCUIApplication().sheets.count returns 0 when the sheet is presented.


Solution

  • It turns out, when using the view debugger, the sheet is accessible via a somewhat hidden accessibilityIdentifier of ActivityListView (as of Xcode 9.2). It can be accessed with:

    XCUIApplication().otherElements["ActivityListView"]
    

    Note that the "Cancel" button is added to the window separately, so it not a child of the activity controller and must be accessed with

    XCUIApplication().buttons["Cancel"]