Ui Testing Failure - Neither Element Nor Any Descendant Has Keyboard Focus on Securetextfield

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.

Fastlane Scan Failed to synthesize event when running UI Tests, works from Xcode

So I figured this out in the end. The tests were working fine.

But I had disable_slide_to_type: true in my scan call, which was causing some weird behaviour it seems.

I also added the following before attempting to type:

extension XCUIElement {
var isFocused: Bool {
let isFocused = (self.value(forKey: "hasKeyboardFocus") as? Bool) ?? false
return isFocused
}
}

if textField.isFocused == false {
textField.tap()
}

And it seems to be working 100% of the time now.

Every time Apple release a new XCode version my UI tests fail

You should not stick to the autogenerated code.

Write the test code and elements' description by yourself – this way you test will be more stable.

Try to make your code simpler – it will be easier to maintain.

    let table = app.tables.element
let passwordCell = table.cells["Password"]
passwordCellsQuery.tapAndType("12345678")

let dateCell = table.cells["Memorable Date (dd/mm/yyyy)"]
dateCell.secureTextFields.element(boundBy: 2).tapAndType("1")
dateCell.secureTextFields.element(boundBy: 0).tapAndType("2")
dateCell.secureTextFields.element(boundBy: 1).tapAndType("3")
extension XCUIElement {
func tapAndType(_ text: String) {
tap()
typeText(text)
}
}


Related Topics



Leave a reply



Submit