Xcode 11 XCUITest Failed to get matching snapshots: Error getting main window kAXErrorServerNotFound
I have experienced the same issue with Xcode 11 and realized that the test runner was not getting killed when stopping the tests (or if the test crashed for some reason). Running the tests a second time would spawn a new test runner and at that point I had two runners trying to interact with the same application, leading to this very strange error.
To prove that I did the following:
- Created a UI test that types a long text in a text view
- Ran the test, and manually stopped it when there were a few sentences in the text view
- Manually opened the app in the simulator (not by running the test)
- Observed that random characters were appearing in the text view, even though no tests were running.
The workaround was to quit and reopen the simulator to make sure all processes were getting killed.Hope this solves your issues
I meet the issue from time to time in Xcode 11.1. I observed that the issue happen when waiting for UI elements especially there are web view being shown during the test. When the issue happened I was using
XCUIElement.waitForExistence(timeout:) or expectation with
NSPredicate(format: "exists == true"). When I changed to use expectation with
NSPredicate(format: "hittable == true") the issue seems to be gone but I don't know why. The difference between the 2 attributes is that
hittable only detect onscreen elements while
exists detect off-screen elements such as off-screen cells of a table view.
expectation(for: NSPredicate(format: "hittable == true"), evaluateWith: element, handler: nil)waitForExpectations(timeout: 60, handler: nil)