Search code examples
iosxcode-ui-testingios14xcode12

How to get access into push notification with UI tests (Xcode 12, iOS14)?


I'm during migration to work with new Xcode 12, but I have a problem with UI tests. Code

let springBoard = XCUIApplication(bundleIdentifier: appleBundleIdentifier) let notification = springBoard.otherElements["NotificationShortLookView"]

not working anymore and I can't find how to indicate notification view. How was it changed?


Solution

  • It seems like notification elements have a slightly different accessibility hierarchy in iOS 14. This should work:

    let springBoard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
    let notification = springBoard.otherElements["Notification"].descendants(matching: .any)["NotificationShortLookView"]
    

    It's interesting to observe that the actual XCUIElement that represents the push notification has type "BannerNotification" (an XCUIElementType with a rawValue representation 83) which I couldn't find in the public headers. Might be a private type at the moment. Hence the workaround with decendants(matching: .any).