I have a very simple XCTestCase
implementation that tests a tap on a button and expects an Alert controller to show up. The problem is that the tap()
method doesn't work. Placing a breakpoint in the associated button's IBAction I realise the logic doesn't even get called.
class uitestsampleUITests: XCTestCase {
var app: XCUIApplication!
override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launch()
}
func testButton() {
let button = app.buttons["Button"]
button.tap()
expectationForPredicate(NSPredicate(format: "exists == 1"), evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5.0, handler: nil)
}
}
Also, duplicating the button.tap()
instruction makes the test pass, like this:
func testButton() {
let button = app.buttons["Button"]
button.tap()
button.tap()
expectationForPredicate(NSPredicate(format: "exists == 1"), evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5.0, handler: nil)
}
I am facing this issue in Xcode 7.3.1 Am I missing something? Is it a bug?
expectationForPredicate(NSPredicate(format: "hittable == 1"), evaluatedWithObject: button, handler: nil)
– Workaday/*Sends a tap event to a hittable/unhittable element.*/ public extension XCUIElement { func forceTapElement() { if self.hittable { self.tap() } else { let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0)) coordinate.tap() } } }
– Cerracchiohittable == 1
is more restrictive thanexists == 1
. WithexpectationForPredicate
sleep
is not needed (not recommended either) – Workadaytap()
twice as a workaround. – WorkadayUIApplication.sharedApplication.beginIgnoringInteractionEvents
? There is an enormous number of problems that could happen. You could log all events inUIApplication.sendEvent
and print your view hierarchy at that time. That should give you some good info. – Palpitationsleep(1)
) did it for me. Thanks! – Pipsqueak