Getting text from TextView in UI test in XCTest
Asked Answered
A

3

7

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?

Adjective answered 16/11, 2016 at 12:16 Comment(0)
A
8

I found the answer. The correct way is:

XCTAssert([textView.value isEqualToString:@"9.9"]);
Adjective answered 16/11, 2016 at 13:38 Comment(0)
I
4

or let text = textView.value as! String

Irmgard answered 30/10, 2017 at 18:13 Comment(1)
complete answer: XCTAssertEqual("9.9", textView.value as? String)Aristippus
U
-2

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...

Uninspired answered 7/5, 2019 at 19:22 Comment(1)
No way! XCTest will never find the textview's text as staticText.Pekingese

© 2022 - 2024 — McMap. All rights reserved.