Reputation: 9660
I am writing a simple UI Test in Xcode and running into issues. I have usernameTextField and passwordTextField. I am not able to refer to the passwordTextField. Here is my test along with the error.
func test_should_create_an_account_and_take_them_to_confirmation_screen() {
let usernameTextField = self.app.textFields["usernameTextField"]
usernameTextField.tap()
usernameTextField.typeText("johndoe")
let passwordTextField = self.app.textFields["passwordTextField"]
passwordTextField.tap()
passwordTextField.typeText("password123")
self.app.buttons["registerButton"].tap()
XCTAssertEqual(self.app.navigationBars.element.identifier, "BankAccount.LoginViewController")
}
Upvotes: 0
Views: 27
Reputation: 10116
As you can see in the error it is able to find the text field just fine, it just can't activate the keyboard.
In Simulator, Hardware > Keyboard > Connect Hardware Keyboard, make sure it is not selected.
Probably you have the username field set to become first responder in viewDidLoad
or something like that so that's why it works for one but not the other.
(I haven't seen a reliable solution for turning off the hardware keyboard programmatically when running tests, but if anyone knows one I would love to know. Unfortunately I think this setting resets when the Simulator is quit.)
Another solution would be to toggle the software keyboard, but with the hardware keyboard disconnected that should be more reliable.
Upvotes: 1