2

I'm trying to run a UI test case where there are two input fields exists. Following is my code

let usernameTextField = app.webViews.otherElements["Identity Server"].textFields["Username"]
let passwordField = app.webViews.otherElements["Identity Server"].secureTextFields["Password"]

_ = usernameTextField.waitForExistence(timeout: 8)

usernameTextField.tap()
usernameTextField.typeText("TEST")  // Breakpoint line

app.typeText("\n")

passwordField.tap()
passwordField.typeText("test")

When I run the test case normally it is failing with the error given in the question title. But if I add a breakpoint to the commented line, it will run without any error.

I tried to use following code snippets after the breakpoint line, separately.

sleep(8)
_ = passwordField.waitForExistence(timeout: 8)

But non of those work. As for further information, this is a Auth process scenario where those input fields resides in a web view.

AnujAroshA
  • 4,623
  • 8
  • 56
  • 99
  • Does this answer your question? [Xcode UI Testing Error keyboard](https://stackoverflow.com/questions/34115375/xcode-ui-testing-error-keyboard) – Sameer Technomark Dec 10 '20 at 21:08
  • An answer to a similar question: [UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField](https://stackoverflow.com/a/65335238/1837959) – storoj Dec 17 '20 at 05:40

2 Answers2

1

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.

AnujAroshA
  • 4,623
  • 8
  • 56
  • 99
  • Interesting, I got the same issue with Xcode 10 Beta 6 and the Simulator. There the keyboard does not come up and `typeText` fails. On an iPhone 5s (iOS 12 Beta) it does work without the `sleep`. On which device / OS are you testing? On all my other devices / simulators with iOS 11 it works without the `sleep`. – cornr Sep 05 '18 at 12:49
-1

Send the \n on the end of the string you send to the username text field:

usernameTextField.typeText("TEST\n")
Oletha
  • 7,324
  • 1
  • 26
  • 46