Reputation: 8406
I have a splash screen that shows for 3 seconds and then fades in to a new view. On this view, there is a UILabel
called "Privacy Policy" that I have attached a UIGestureRecognizer
to. I'm trying to use UI tests to tap on that label to trigger a navigation controller push. This works in real life, however, during UI testing the tap doesn't do anything. My code looks like this:
func testPrivacyPolicyLink() {
let app = XCUIApplication()
let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: app.images["Logo"], handler: nil)
waitForExpectationsWithTimeout(5) { error in
XCTAssertNil(error, "Splash screen took too long")
sleep(4) // Added this just to make sure the splash screen has fully faded away
app.staticTexts["Privacy Policy"].tap() // Should trigger a navigation controller push, but doesn't do anything
}
}
Even when recording a UI test for this situation, it calls app.staticTexts["Privacy Policy"].tap()
which works. But when I play it back, it doesn't work. Any help on this would be appreciated!
Upvotes: 3
Views: 2558
Reputation: 3196
You need to setup accessibility traits for this view to be "Button" or "Link" so it would be clear to the accessibility system that this elements are touchable. You can set it in the Interface Builder, select Identity inspector in the Utilities pane and set Accessibility Identifier and traits classes
alternatively you can do this in code
self.view.accessibilityTraits = UIAccessibilityTraitButton;
self.view.accessibilityIdentifier = "departments selection";
Upvotes: 3