Reputation: 461
After building my app in Xcode 11 and running my suite of XCUITests I am getting many random failures with the following.
Failed to get matching snapshots: Error getting main window kAXErrorServerNotFound
No matter how long I increase timeouts the issues pop up intermittently. It seems to be having issues Snapshotting the UI hierarchy. Our tests pass consistently in Xcode 10.
I have reinstalled Xcode. Deleted all simulators. Cleared derived data. Modified timeouts. Upgraded from Xcode 11.1 to Xcode 11.2.1.
Thanks!
Upvotes: 33
Views: 13434
Reputation: 323
For me, calling activate()
twice was the solution. It's not the first time I have had issues with that. I had other tests that needed to call the app back to the foreground and calling activate
once wasn't enough.
XCUIApplication().activate()
XCUIApplication().activate()
It sounds weird, I know, but give it a try.
Upvotes: 0
Reputation: 974
If you are using fastlane it can be solve easily with the following lane:
# Unit tests
lane :tests do
clear_derived_data
scan(
workspace: "AppTest.xcworkspace",
devices: ["iPhone 8"], # it can be with the iPhone that has your VM
force_quit_simulator: true,
reset_simulator: true,
reinstall_app: true,
scheme: "AppTest"
)
end
In theory, you must reset your simulator and reinstall your app.
Happy coding
Upvotes: 0
Reputation: 648
I had the problem with matching while I was running the simple UITest in Xcode 11.3. To make it work I had to paste at first: XCUIApplication().activate()
or XCUIApplication().launch()
.
Upvotes: 33
Reputation: 1164
I had a similar issue on Xcode 11.
It turned out that before it was allowed to have the same accessibility identifier in many page.
But now using the new modal presentation style, you should use different identifiers within your pages to avoid conflicts.
Upvotes: 0
Reputation: 51
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)
Upvotes: 3
Reputation: 4594
I use different machines. My older Macs experience this error far more often. My guess is older macs do not have the memory required to run certain XCUITests correctly.
Upvotes: 0
Reputation: 480
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:
The workaround was to quit and reopen the simulator to make sure all processes were getting killed. Hope this solves your issues
Upvotes: 7