typeText()输入的字符不一致 [英] typeText() is typing inconsistent characters
问题描述
在编写UI测试的同时,我开始全神贯注于Swift,并且在将文本输入到textField中时遇到了问题.下面是代码:
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)
}
当我执行usernameField.typeText(username)
时出现问题.我的文字继续写tstusername2
而不是testusername2
.
The problem occurs when I do usernameField.typeText(username)
. My text continues to write tstusername2
rather than the testusername2
.
推荐答案
启用硬件键盘后,模拟器上会发生此问题.
This issue happens on the simulator when the Hardware Keyboard is enabled.
转到I/O->键盘->取消选中连接硬件键盘"或使用快捷键⇧⌘K.
Go to I/O -> Keyboard -> Uncheck "Connect Hardware Keyboard" or use the shortcut ⇧⌘K.
如果您想为您的Scheme禁用硬件键盘,无论您运行哪种模拟器,请参考此 StackOverflow帖子.我尝试使用其他方法通过App Delegate禁用硬件键盘,但是没有运气.
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.
这篇关于typeText()输入的字符不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!