Why do XCTest UI tests sometimes fail with the error "Failed to get confirmation of event delivery within [n seconds] of the original send",

I have a fairly normal XCTest UI test for a Mac application that clicks some menu items on the application menu to open a window.

In some places - like my own Mac - tests work fine. But in other places - for example, on Travis CI - they fail, with this error:

 UI Testing Failure - Failed to receive event delivery confirmation within 2.5s of the original dispatch. ... menuBarsQuery.menuBarItems["Top level menu item"].click() menuBarsQuery.menuItems["Menu item in sub menu"].click() 

System:

  • Mac OS 10.11.5
  • Xcode 7.2.1
  • Mac OS SDK Version: 10.11.2
  • Swift 2.1.1

Lightly sanitized version of the test case:

 import XCTest class FooUITests: XCTestCase { override func setUp() { super.setUp() continueAfterFailure = false XCUIApplication().launch() } override func tearDown() { super.tearDown() } func testCanDoSomething() { let app = XCUIApplication() let menuBarsQuery = app.menuBars menuBarsQuery.menuBarItems["Top level menu item"].click() menuBarsQuery.menuItems["Menu item in sub menu"].click() let window = app.windows["Foo"] // Rest of test, assertions, actions in window etc. } } 

It doesn’t play locally, so I’ll ask the audience ... why will this error happen?

+5
source share

All Articles