Im working on with XCUITest, where in its a simple screen, having just username textField, password textField and a Login Button. I could able assert like on tap of Login button, both username textField and Password textField is non empty. But what to do something like, i want to typeText in username and password textFields. Which is possible on first field only as im getting error with below code.
func testUserNameShouldNotBeEmptyOnLoginButtonTapped() {
app.launch()
let loginButton = app.buttons["Login"]
let userNameField = app.textFields["UsernameTextField"]
userNameField.tap()
userNameField.typeText("Dummy User")
sleep(2)
let passwordField = app.textFields["PasswordTextField"]
passwordField.tap()
passwordField.typeText("Yohooooooso")
loginButton.tap()
XCTAssertTrue(userNameField.exists)
guard let userNameValue = userNameField.value as? String,
let passwordValue = passwordField.value as? String else {
XCTAssert(true, "UsernameTextFieldUsernameTextFieldUsernameTextField")
return
}
if passwordValue.isEmpty {
XCTAssert(false, "Password Cannot be Empty")
} else if userNameValue.isEmpty {
XCTAssert(false, "UserName Cannot be empty")
} else {
XCTAssert(true, "Both Fields are valid")
}
}
How can i able to change the focus of Keyboard to select field or i hide keyboard on done with the typeText
on first field.
Im getting the exception on the passwordTextField as below
Neither element nor any descendant has keyboard focus. Event dispatch snapshot: TextField, identifier: 'PasswordTextField'