简体   繁体   English

typeText 方法的 SwiftUI TextEditor UI 测试失败

[英]SwiftUI TextEditor UI Testing Failure for typeText method

"typeText" method is working for 'TextField' element but not working for the 'TextEditor' element in the Xcode UI Tests. “typeText”方法适用于“TextField”元素,但不适用于 Xcode UI 测试中的“TextEditor”元素。 Connecting Hardware Keyboard options (enable/disable) were tried and no success.尝试连接硬件键盘选项(启用/禁用)但没有成功。 Any workarounds?任何解决方法?

Failed to synthesize event: Neither element nor any descendant has keyboard focus.合成事件失败:元素和任何后代都没有键盘焦点。 Event dispatch snapshot: TextView, identifier: 'content'事件调度快照:TextView,标识符:'content'

let nameTextField = app.textFields["name"]
nameTextField.tap()
nameTextField.typeText("Test Name") // Working 

let contentTextEditor = app.textViews["content"]
contentTextEditor.tap() // It successfully makes the cursor focus on the TextEditor element 
contentTextEditor.typeText("Test Content") // Here is the error

Perhaps you could try pasting instead?也许你可以尝试粘贴?

let contentTextEditor = app.textViews["content"]
UIPasteboard.generalPasteboard().string = "Test Content"
contentTextEditor.doubleTap()
app.menuItems.elementBoundByIndex(0).tap() // This is the ugly, but correct way to hit the paste button
XCTAssertEqual(contentTextEditor.value as? String, "Test Content")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM