2

For iOS11, I used the following to access the Face Not Recognized system alert within my UI Test:

XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.firstMatch

This is not working for me in iOS12. The alert is not showing up anymore in the Element tree.

Does anyone know how I can access this now in iOS12?

enter image description here

This is from iOS11 element tree: enter image description here

This is result of po XCUIApplication(bundleIdentifier: "com.apple.springboard") for iOS12:

    Attributes: Application, pid: 30484, label: ' '
Element subtree:
 →Application, 0x60000105c000, pid: 30484, label: ' '
    Window, 0x60000105c0d0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x60000105c1a0, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x60000105c270, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x60000105c340, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x60000105c410, {{0.0, 0.0}, {414.0, 896.0}}
    Window, 0x60000105c4e0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x60000105c5b0, {{0.0, 0.0}, {0.0, 0.0}}
        Icon, 0x60000105c680, {{-2.3, -2.0}, {70.0, 91.3}}
        Icon, 0x60000105c750, {{-2.0, -2.0}, {68.0, 91.3}}
        Icon, 0x60000105c820, {{-2.0, -2.0}, {68.0, 91.3}}
        Icon, 0x60000105c8f0, {{-2.0, -2.0}, {68.0, 91.3}}
        Icon, 0x60000105c9c0, {{-2.0, -2.0}, {68.0, 91.3}}
        Icon, 0x60000105ca90, {{-2.0, -2.0}, {68.0, 91.3}}
        Icon, 0x60000105cb60, {{-2.0, -2.0}, {68.0, 91.3}}
      Other, 0x60000105cc30, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x60000105cd00, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x60000105cdd0, {{0.0, 0.0}, {414.0, 100.0}}
          Other, 0x60000105cea0, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x60000105cf70, {{0.0, 0.0}, {414.0, 896.0}}
    Window, 0x60000105d040, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x60000105d110, {{0.0, 0.0}, {414.0, 896.0}}
    Window, 0x60000105d1e0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x60000105d2b0, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x60000105d380, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x60000105d450, {{0.0, 0.0}, {414.0, 896.0}}
            Other, 0x60000105d520, {{0.0, 0.0}, {414.0, 896.0}}
              Other, 0x60000105d5f0, {{0.0, 0.0}, {414.0, 896.0}}
                Other, 0x60000105d6c0, {{0.0, 0.0}, {414.0, 896.0}}
                  Other, 0x60000105d790, {{0.0, 0.0}, {414.0, 896.0}}
                    Other, 0x60000105d860, {{0.0, 0.0}, {414.0, 896.0}}
                      Other, 0x60000105d930, {{0.0, 0.0}, {414.0, 896.0}}
                        Other, 0x60000105da00, {{0.0, 0.0}, {414.0, 896.0}}
                        Other, 0x60000105dad0, {{0.0, 0.0}, {414.0, 896.0}}
                          Other, 0x60000105dba0, {{0.0, 0.0}, {414.0, 896.0}}
                            Other, 0x60000105dc70, {{0.0, 0.0}, {414.0, 896.0}}
                            Other, 0x60000105dd40, {{0.0, 0.0}, {414.0, 896.0}}
                            Other, 0x60000105de10, {{0.0, 0.0}, {414.0, 896.0}}
                        Other, 0x60000105dee0, {{0.0, 0.0}, {414.0, 896.0}}
                          Other, 0x60000105dfb0, {{0.0, 0.0}, {414.0, 896.0}}
                            Other, 0x60000105e080, {{0.0, 0.0}, {414.0, 896.0}}
    Other, 0x60000105e150, {{0.0, 0.0}, {1242.0, 2688.0}}
      Other, 0x60000105e220, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105e2f0, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105e3c0, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105e490, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105e560, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105e630, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105e700, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105e7d0, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105e8a0, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105e970, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105ea40, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105eb10, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105ebe0, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105ecb0, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105ed80, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105ee50, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105ef20, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105eff0, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105f0c0, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105f190, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105f260, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105f330, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105f400, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105f4d0, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105f5a0, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105f670, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105f740, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105f810, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105f8e0, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105f9b0, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105fa80, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105fb50, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105fc20, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x60000105fcf0, {{0.0, 0.0}, {1242.0, 2688.0}}
        Other, 0x60000105fdc0, {{0.0, 0.0}, {1242.0, 2688.0}}
          Other, 0x60000105fe90, {{0.0, 0.0}, {1242.0, 2688.0}}
            Other, 0x600001063190, {{0.0, 0.0}, {1242.0, 2688.0}}
      Other, 0x600001062d80, {{0.0, 0.0}, {1242.0, 2688.0}}
    Window, 0x600001063260, {{0.0, 0.0}, {414.0, 896.0}}, identifier: 'SBSwitcherWindow'
      Other, 0x600001062f20, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x600001062ff0, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x600001062e50, {{0.0, 0.0}, {414.0, 896.0}}
            Other, 0x600001063dc0, {{0.0, 0.0}, {414.0, 896.0}}
              ScrollView, 0x600001063e90, {{0.0, 0.0}, {414.0, 896.0}}
              Other, 0x600001062cb0, {{0.0, 0.0}, {414.0, 896.0}}, identifier: 'AppSwitcherContentView'
                Other, 0x600001063330, {{0.0, 0.0}, {414.0, 896.0}}, label: 'App', value: Active
                  ScrollView, 0x600001063c20, {{0.0, -448.0}, {414.0, 1344.0}}
                    Other, 0x600001062150, {{0.0, 0.0}, {414.0, 996.0}}
                      Other, 0x600001062560, {{0.0, 0.0}, {414.0, 896.0}}
                      Other, 0x600001061ba0, {{0.0, 0.0}, {414.0, 896.0}}
                        Other, 0x600001061c70, {{0.0, 0.0}, {414.0, 896.0}}
                          Other, 0x600001062220, {{0.0, 0.0}, {414.0, 896.0}}
                            Other, 0x600001062630, {{0.0, 0.0}, {414.0, 896.0}}
                              Other, 0x600001061fb0, {{0.0, 0.0}, {414.0, 896.0}}
                                Other, 0x600001061e10, {{0.0, 0.0}, {414.0, 896.0}}
                      Other, 0x600001062be0, {{0.0, 0.0}, {414.0, 896.0}}
    Window (Main), 0x600001061ee0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x600001063670, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x600001063740, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x600001062700, {{0.0, 0.0}, {414.0, 896.0}}
            Other, 0x600001062490, {{0.0, 0.0}, {414.0, 896.0}}
              Other, 0x600001061040, {{0.0, 0.0}, {414.0, 896.0}}
                Other, 0x600001062080, {{0.0, 0.0}, {414.0, 896.0}}
                  Other, 0x6000010639b0, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x6000010628a0, {{0.0, 0.0}, {414.0, 896.0}}, identifier: 'Home Grabber'
            Other, 0x600001063a80, {{133.0, 883.0}, {148.0, 5.0}}
    Window, 0x6000010638e0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x600001061d40, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x6000010627d0, {{0.0, 896.0}, {414.0, 243.0}}
        Other, 0x600001063400, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x6000010635a0, {{0.0, 0.0}, {414.0, 896.0}}
    Window, 0x600001063b50, {{-0.0, -0.0}, {414.0, 896.0}}
      Other, 0x600001063cf0, {{-0.0, -0.0}, {414.0, 896.0}}
        Other, 0x600001063810, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x6000010634d0, {{-0.0, -0.0}, {414.0, 896.0}}
    Window, 0x600001062b10, {{0.0, 0.0}, {414.0, 896.0}}
    Window, 0x6000010630c0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x600001062970, {{0.0, 0.0}, {414.0, 896.0}}
    Window, 0x6000010622f0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x6000010623c0, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x600001062a40, {{0.0, 0.0}, {0.0, 0.0}}
Path to element:
 →Application, pid: 30484, label: ' '
Query chain:
 →Find: Application 'com.apple.springboard'
  Output: {
    Application, pid: 30484, label: ' '
  }
reutsey
  • 1,743
  • 1
  • 17
  • 36
  • I clearly see "Try Face ID Again" button in the hierarchy as well as any other alert elements – artyom.razinov Feb 03 '19 at 14:25
  • For iOS12? The element tree shown is for iOS11, but I'm not seeing it in iOS12. – reutsey Feb 04 '19 at 01:57
  • Can you print `XCUIApplication(bundleIdentifier: "com.apple.springboard")` (it should print element tree)? Also, I have UI tests on springboard and I use private API: `XCUIApplication(privateWithPath: nil, bundleID: "com.apple.springboard")`. And my tests work with alerts (alert about deletion of app). To expose this private initializer, add `- (id)initPrivateWithPath:(id)arg1 bundleID:(id)arg2;` in Obj-C extension to XCUIApplication. – artyom.razinov Feb 04 '19 at 09:46
  • So i noticed I only have an issue with the Face Not Recognized system alert. I updated my issue above and I also added the output of the printed springboard bundle. – reutsey Feb 06 '19 at 00:47

2 Answers2

0

Try XCUIApplication(privateWithPath: nil, bundleID: "com.apple.springboard").coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(). Maybe you have to play with values of offset.

If it leads to cancelling an alert then you at least can cancel this alert. This could be so if alert is handled by UIInterruptionMonitor.

In that case use addUIInterruptionMonitor: https://developer.apple.com/documentation/xctest/xctestcase/1496273-adduiinterruptionmonitor


There is a way to not trigger UIInterruptionMonitor and tap on coordinate, but for that you should find XCUIElement for alert and tap on its coordinate, tapping on any other element triggers UIInterruptionMonitor.


If UIInterruptionMonitor doesn't work then you can tap on coordinate. Hardcoded coordinate can be ok, but you can not detect if alert is displayed or not.

To get precise coordinate and check if anything is displayed on the screen, you can find image in image: image of your button on the screenshot of the screen: https://gist.github.com/artyom-razinov/f5b190e2a5f3282eb0b5c1191a1bc674

The algorithm in the code requires 100% match of pixels of image and it may require to have snapshots of a button for every device (however if someone will write SIFT algorithm for UIImage and CGRect in Swift, it can use 1 image for every device, because SIFT is Scale Invariant Feature Transform).


Maybe this alert doesn't exist in springboard's app hierarchy, but somehow exists in other app hierarchy.


Advice: do not mind about automating this test. It is okay to have some manual tests.

artyom.razinov
  • 610
  • 3
  • 17
0

Possibly a timing issue which could be resolved as follows:

let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")


let firstButton  = springboard.buttons.firstMatch
//let secondButton = springboard.buttons.element(boundBy: 1)   // index: 0, 1, …
//let namedButton  = springboard.alerts.buttons["Some String"] // another example

if firstButton.waitForExistence(timeout: 6) {
    firstButton.tap() // do something after button exists
}
marc-medley
  • 8,931
  • 5
  • 60
  • 66