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

Solution 1:

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.

Solution 2:

Recently we found a hack to make solution from accepted answer persistent. To disable Simulator setting: I/O -> Keyboard -> Connect hardware keyboard from command line one should write:

defaults write com.apple.iphonesimulator ConnectHardwareKeyboard 0

It will not affect a simulator which is running - you need to restart simulator or start a new one to make that setting have its effect.

Solution 3:

I have written a small extension (Swift) which works perfect for me. Here is the code:

extension XCTestCase {

    func tapElementAndWaitForKeyboardToAppear(element: XCUIElement) {
        let keyboard = XCUIApplication().keyboards.element
        while (true) {
            element.tap()
            if keyboard.exists {
                break;
            }
            NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 0.5))
        }
    }
}

The main idea is to keep tapping an element (text field) before the keyboard is presented.

Solution 4:

Stanislav has the right idea.

In a team environment, you need something that will automatically work. I've come up with a fix here on my blog.

Basically you just paste:

UIPasteboard.generalPasteboard().string = "Their password"
let passwordSecureTextField = app.secureTextFields["password"]
passwordSecureTextField.pressForDuration(1.1)
app.menuItems["Paste"].tap()