Xcode UI Testing Error Keyboard

UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField

This issue caused me a world of pain, but I've managed to figure out a proper solution. In the Simulator, make sure I/O -> Keyboard -> Connect hardware keyboard is off.

Neither element nor any descendant has keyboard focus when running XCTestCase in a real iPhone

I decided to answer myself rather than closing the question. I'll tell what went wrong in my code. The main mistake I have done was continueAfterFailure set as true. Because of that, the error shown in the wrong line not the actual error throwing line.

So the solution is,

continueAfterFailure = false

and

usernameTextField.tap()
sleep(2)
usernameTextField.typeText("TEST")

There should be a small waiting time till keyboard appears in the web view before type text.

how to Detect if Keyboard is shown in Xcode UI test

Add two observers

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardVisible:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardHidden:", name: UIKeyboardDidHideNotification, object: nil)

func keyboardVisible(notif: NSNotification) {
print("keyboardVisible")
}

func keyboardHidden(notif: NSNotification) {
print("keyboardHidden")
}

Whenever the keyboard is visible keyboardVisible will be called and whenever the keyboard is hidden keyboardHidden will be called.



Related Topics



Leave a reply



Submit