XCUITest and UIActivityViewController
Asked Answered
O

2

2

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.

Overseas answered 25/1, 2018 at 19:33 Comment(0)
O
9

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"]
Overseas answered 25/1, 2018 at 19:33 Comment(2)
Has this changed for iOS 13? This doesn't work when running my test on iOS 13 simulators anymore.Diner
@Diner this still works on iOS 15.0. You can check the identifier by typing 'po app' in the console.Convexoconcave
M
0

Tested on xcode 12.2 with iOS 14.2:

XCUIApplication().otherElements.element(boundBy: 1).buttons.element(boundBy: <insert button index here>).tap()

Possible button index numbers:

  • 0: Cancel
  • 1: Copy
  • 2: Markup
  • 3: Print
  • 4: Save to files
Mcknight answered 11/12, 2020 at 9:7 Comment(1)
This approach I get the following error: Failed to synthesize event: Failed to scroll to visible (by AX action) Button, error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 3118, elementOrHash.elementID: 4354340448.106. (Underlying Error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 3118, elementOrHash.elementID: 4354340448.106) Maieutic

© 2022 - 2025 — McMap. All rights reserved.