First call to tap on a button in a tab bar fails in UI tests

Originator:gps
Number:rdar://26493495 Date Originated:05/26/2016
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification:Serious Bug Reproducible:Always
 
Summary:
When writing a UI test for a tab bar application, calling tap on a tab bar button does not work the first time. Calling tap again does, as does inserting an artificial delay before calling tap.

See attached Xcode projects. One fails (this is how I would expect the test to be written), and two work (both "fixes" are hacks).

An artificial delay shouldn't be required to get tests to pass, since figuring out the right delay to put in would be very hard (would depend on the speed of the hardware the test is running on), and the tests would be artificially slowed down.

Steps to Reproduce:
- Create a new iOS Xcode project, with the "Tabbed Application" Template
- Turn on UI Tests
- Write a UI test that looks like this:
    func testTappingOnTabBar() {
        let tabBar = XCUIApplication().tabBars
        tabBar.buttons["Second"].tap()
        XCTAssertTrue(tabBar.buttons["Second"].selected)
    }
- Run tests on an iPhone 6 Plus simulator



Expected Results:
Test should pass on all simulators, all the time.

Actual Results:
Test always fails on iPhone 6 Plus and iPhone 6S Plus simulators. Test passes most of the time on iPhone 6 and iPhone 6S simulators, but still fails sporadically.

Version:
Xcode: Version 7.3.1 (7D1014)
OS X: 10.11.5 (15F34)

Comments

Xcode projects to demonstrate the problem:

https://dl.dropboxusercontent.com/u/724103/TabBarUITests%20-%20Fails.zip

https://dl.dropboxusercontent.com/u/724103/TabBarUITests%20-%20Works%20%281%29.zip

https://dl.dropboxusercontent.com/u/724103/TabBarUITests%20-%20Works%20%282%29.zip


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!