Fixing Xcode 9 UI tests

After switching to Xcode 9 on our CI extended UI tests started failing. It turned out that referencing elements from navigation bars set in storyboards by image name stopped working.

I'm not a fan of such approach in the first place, but there's no way to set accessibility identifier from Xcode's interface builder. UIBarButtonItem does implement UIAccessibilityIdentification but there's no way to change its values.

Two ways of solving that is either by adding it manually to "User Defined Runtime Attributes" yourself

Or you can add small workaround extension to your project:

extension UIBarButtonItem {

    // Workaround for Xcode to show option to specify accessibility identifier from IB
    // Read more: http://blog.pendowski.com/fixing-xcode-9-ui-tests
    @IBInspectable
    var xcode_accessibilityIdentifier: String? {
        get { return accessibilityIdentifier }
        set { accessibilityIdentifier = newValue }
    }
}

and edit it nicely from the UI: