Yulia
Yulia

Reputation: 1242

Getting text from TextView in UI test in XCTest

I'm trying XCode for iOS UI testing. My test application has UITextView element with accessibility identifire displayTextView.

I tried simple test that taps this element, types some text it and then check the result the following way:

XCUIElement *textView = app.textViews[@"displayTextView"];
[textView tap];
[textView typeText:@"9.9"];

It works. But then I can't get the typed text from the text view. I tried to do it by the following:

XCTAssertEqual([textView.accessibilityValue isEqualToString:@"9.9"]);

But it seems it is incorrect, because textView.accessibilityValue is null. What method would be appropriate to get the typed text?

Upvotes: 7

Views: 7702

Answers (3)

Zeck
Zeck

Reputation: 317

I used:

let expectedValue = "Hello World!"
XCTAssert(app.staticTexts[expectedValue].isHittable)

Using this approach, we look for labels displaying expectedValue, and verify if it is visible...

Upvotes: -2

David Weiss
David Weiss

Reputation: 1782

or let text = textView.value as! String

Upvotes: 4

Yulia
Yulia

Reputation: 1242

I found the answer. The correct way is:

XCTAssert([textView.value isEqualToString:@"9.9"]);

Upvotes: 8

Related Questions