Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 284
Yulia Avatar asked Nov 16 '16 12:11

Yulia


2 Answers

I found the answer. The correct way is:

XCTAssert([textView.value isEqualToString:@"9.9"]);
like image 116
Yulia Avatar answered Sep 19 '22 02:09

Yulia


or let text = textView.value as! String

like image 27
David Weiss Avatar answered Sep 18 '22 02:09

David Weiss