typeText() is typing inconsistent characters

喜你入骨 提交于 2020-04-18 06:09:40

问题


I'm beginning to dip my toes into Swift alongside writing UI tests and am having a problem with typing text into a textField. Below is the code:

func testLoginUsernameField() {
    let app = XCUIApplication()
    app.launch()

    let username = "testusername2"

    let usernameField = app.textFields["username_field"]
    XCTAssertTrue(usernameField.exists)

    usernameField.tap()
    usernameField.typeText(username)
    XCTAssertEqual(usernameField.value as! String, username)
}

The problem occurs when I do usernameField.typeText(username). My text continues to write tstusername2 rather than the testusername2.


回答1:


This issue happens on the simulator when the Hardware Keyboard is enabled.

Disable the hardware keyboard via the menu

Go to I/O -> Keyboard -> Uncheck "Connect Hardware Keyboard" or use the shortcut ⇧⌘K.

Disable the hardware programmatically

If you'd like to disable the hardware keyboard for your Scheme, no matter what simulator you run, refer to this StackOverflow post. I attempted to use other methods to disable the hardware keyboard via the App Delegate but had no luck.



来源:https://stackoverflow.com/questions/60688727/typetext-is-typing-inconsistent-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!