XCTest UI Testing; boundElementsByIndex stale the main thread

Hi community:

I found that after Xcode update from 14.3.1 to 15.0.1, my UITests fail only on the CI (Apple Xcode Cloud) because the use of boundElementsByIndex.

Seems that the use of this property stale the main thread:

Failed to resolve query: Unable to perform work on main run loop, process main thread busy for 30.0s

Is it a known issue?

Thanks

I'm having the same, it started happening when switching build env to Sonoma. This issue is here for several Xcode and OS X versions and not fixed yet. The outcome is the same for all testing devices and all iOS versions, it only depends on running OS X version - Sonoma. For me it happens when i'm trying to activate the text field inside the presented view controller. Sometimes it may work when you log some info from boundElementsByIndex (seems like it helps to connect properly to the view hierarchy or something) but sometimes it just freezes on the boundElementsByIndex call like it does for you. I can tell you more, I've reworked the UI from UIKit to SwiftUI, completely rewritten all the screen logic and UI and got the same result, so it's not something about your code, XCTest bug. Can you confirm that togethere with Xcode you've updated your os version to Sonoma?

Thank you so much for this! I was stuck on this failure happening in Xcode Cloud only with this function:

func hideKeyboardIfExists(app: XCUIApplication) {
    if app.keyboards.element(boundBy: 0).exists {
        app.keyboards.buttons["Hide keyboard"].tap()
    }
}

For some reason, the test would fail with "Checking existence of Keyboard (Element at index 0)" and then retry 1 and retry 2 at 30 second intervals which was very mysterious. The keyboard was on screen according to the simulator replay, so it's strange that it would fail to find it, and also strange that it would get stuck in a retry loop instead of simply skipping the if clause.

Based on this post, I downgraded the Xcode Cloud workflow to Ventura 13.6.3 and Xcode 14.3.1 and then the simulator to iOS 16.4. (The error was occurring with Xcode Cloud workflow specifying Sonoma 14.1.2, Xcode 15.2 and simulator iOS 17.2.) And voila that error is gone! How come Apple hasn't fixed this yet?

Nothing, I've submitted 2 major Xcode Cloud issues to Apple 2 month ago, still no response on a single one. One of them was about that keyboard-related freeze. I've met several reports on similar freezes around the net, none of them had any solutions. Feels like ppl are not too much into UI testing on cloud to get enough of those bugs for Apple to start doing something with that, but as this is happening with 100% repro and cannot be dodged by any kind of tricks/refactoring I hope this will become a big enough deal for someone to resolve this. I bet the repro shouldn't be too hard. Had anyone tried to isolate the bug in a sandbox project?

I'm curious if app.keyboards.firstMatch has the same result for you?

I know it may freeze even before the keyboard is show, like you can just print application.textFields.firstMatch and test freezes during this, you don't even has to perform some UI action, just a lookup freezes. It's a huge issues and it's up for like half of the year, I've submitted several reports about this to Feedback Assistant + Developer support email. The only response I've got through to my huge detailed request for help - I've got a link to https://developer.apple.com/support/xcode/ website with a comment "We highly recommend that you check out this article". That's it! I got all them reports case numbers, all them feedback assistant cases - noone cares. I'm literally left without any help, not just me, lots of people are reporting the same issue, noone every found a solution or got assisted by Apple

Any luck with this? We've been having the same issue since Oct 2023 and haven't been able to resolve it.

We've been forced to occasionally run UI tests locally on our failing tests to ensure that they're still passing as well as put hundreds of dev hours into trying to come up with our own solution.

If you provide the Feedback number (or numbers) here I would be happy to personally investigate this issue.

XCTest UI Testing; boundElementsByIndex stale the main thread
 
 
Q