How can I avoid NSInternalInconsistencyException when tapping on UI elements with XCTest? How can I avoid NSInternalInconsistencyException when tapping on UI elements with XCTest? swift swift

How can I avoid NSInternalInconsistencyException when tapping on UI elements with XCTest?


In Xcode 9, this can be caused due to a bug between XCUITest and the new Xcode 9 main thread checker. More details are in this blog post.

To temporarily work around this issue until Apple fixes it, disable the Main Thread checker in the Test section of your scheme:

enter image description here


I ended up fixing this by retaining the element and just using the same reference to it for subsequent calls.

XCUIElement *searchBar = self.app.searchFields[@"Search"];[searchBar tap];[searchBar typeText:@"Test Guy"];


I had same issue with my XCUItestcase. Though I unselected "Main Thread checker" in schema settings but still my test case was failing. The strange thing that it was passing on iphone 6 plus but same code was failing for 5s, 6s iphone. Here is the approach I took to resolve the issue:

1. Make sure you 'unselected "Main Thread checker" in test targetscheme settings2. Take the reference of the UI element where test is crashing.3. Before performing action. Put some sleep or have some delay.4. Then perform the action on that element.

schema settings tes schema settings

sample :

   let confirmBtn = app.buttons["go"]   sleep(2)   confirmBtn.tap()