How do you type into a UITextView
inside a XCTestCase
? The UITextView
is the first responder so it already had focus and the keyboard is up.
I've tried:
app.typeText("footer")
app.textViews.element(boundBy: 0).typeText("foobar")
app.links.element(boundBy: 0).typeText("foobar")
for some reason app.textViews.count
always returns 0
?
The problem is not that .typeText(_:)
doesn't work, it's that your query doesn't resolve to an element.
It can sometimes seem like the query is not working properly when the view you're trying to find is inside an accessible container view of some sort. You can mitigate this by explicitly disabling accessibility in the container view.
Set the stack view that contains the text view to not be an accessibility element and then set an accessibility identifier on the text view.
// app code
let stack: UIStackView!
let textView: UITextView!
stack.isAccessibilityElement = false
textView.isAccessibilityElement = true
textView.accessibilityIdentifier = "myTextView"
// test code
let app = XCUIApplication()
let textView = app.textViews["myTextView"]
textView.typeText("something")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With