SwiftUI TextEditor UI Testing Failure for typeText method

Viewed 442

"typeText" method is working for 'TextField' element but not working for the 'TextEditor' element in the Xcode UI Tests. 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'

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
1 Answers

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")
Related