Xcode 14 beta 3 View Heirarchy differs in Running vs XCUITest

Running our app on Simulator or iOS 16 real device behaves as expected from Xcode. Running an XCUITest suddenly screws up the view heirarchy, so things that get tapped are incorrect.

The UI has a list of cells for files. On the far right of each cell is a kabob UIButton with a UIImageView of the kabob image. In previous versions of running this app, if I clicked on the kabob, a cell would popup with choices. In Xcode 14b3, the tap goes to the file cell, which instead launches the file in an editor.

What's really strange is that running the app from Xcode, all is fine. But Build-for-Test and running the XCUITest and it screws up.

We have run into a similar problem and it still seems to be the case in Xcode 14 beta 4. In our case, we rely heavily on screen coordinates for testing. It seems that on iOS 16 devices only, XCUITest is returning pixels instead of points. In other words, the coordinates are multiplied by the scale of the device screen. For example, I ran the same UI test on Xcode 14 beta 3 (and 4) against two iPhone 11 simulator devices, one using iOS 15.5, the other using iOS 16.0. Here is the relevant part of the test:

    func testExample() throws {
        let app = XCUIApplication()
        app.launch()
        let button = app.tabBars["Tab Bar"].buttons["Debug"]
        let location = button.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).screenPoint
        print("Button location: \(location)")
    }
  • On iOS 15.5, this prints: Button location: (207.0, 838.0)
  • On iOS 16.0, this prints: Button location: (414.0, 1676.0)

If this is an intentional change on Apple’s part, they need to say so in the release notes.

Xcode 14 beta 3 View Heirarchy differs in Running vs XCUITest
 
 
Q