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
How to Get Memory Usage in Swift
How to Convert Fbprofilepictureview to an Uiimage
iOS Swift: How to Change the Font Style of a Certain Word in a String
App Updates, Nsurl, and Documents Directory
Firebase Listener When App Is in the Background
Is It Ok to Place Most Logic and Models in the Appdelegate
Why Is Allocating or Initializing Nsdateformatter Considered "Expensive"
Present Uialertcontroller from Appdelegate
Cannot Import Firebase into Swift Class
How to Add an Identifier to Auto Layout Constraints in Interface Builder
Error in Xcode 6 - View Controller Does Not Have an Outlet Named (Subview)
Add a Child View Controller's View to a Subview of the Parent View Controller
Get Name of Airplay Device Using Avplayer
Asset Catalog: Access Images with Same Name in Different Folders