How to enter UITextView inside XCTestCase

How do you UITextView inside an XCTestCase ? UITextView is the first responder, so it already has focus and keyboard up.

I 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 ?

+5
source share
2 answers

The problem is not that .typeText(_:) not working, it means that your request does not allow the element.

Sometimes it may seem that the request is not working properly when the view you are trying to find is inside an accessible container view. You can reduce this by explicitly disabling accessibility in the container view.

Set the stack view that contains the text view so that it is not an accessibility element, and then set the accessibility identifier in 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") 
+5
source

Try setting a unique accessibility identifier for your UITextView , and then:

 let textView = app.textViews["uniqueId"] XCTAssert(textView.exists, "uniqueId text view NOT FOUND") textView.tap() textView.typeText("foobar") 
+3
source

Source: https://habr.com/ru/post/1268487/


All Articles