Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Assert TextView value in XCode7 iOS9?

I am doing an UI Unit Testing. In the picture.
They are UILabels except long description which is UITextView.
In the page I want to do assert test the value in the answer.

For the answer in the UILabels are fine. I can follow Xcode UI Test example
The method is pretty easy to follow just tap on the element and change method from .tap() to .exist() Then enclose it by assert();

My problem is UITextView is more complicated than UILabel.
How can I get the value of UITextView in order to do assert check?

func testG(){

let app = XCUIApplication()
app.launch();
app.buttons["Enter"].tap()
app.tables.staticTexts["Bee"].tap()

assert(app.scrollViews.staticTexts["Name :"].exists);
assert(app.scrollViews.staticTexts["Age :"].exists);
assert(app.scrollViews.staticTexts["Specialty :"].exists);
assert(app.scrollViews.staticTexts["Description :"].exists);

assert(app.scrollViews.staticTexts["Bee"].exists);
assert(app.scrollViews.staticTexts["11"].exists);
assert(app.scrollViews.staticTexts["Sky Diver"].exists);
let text = "Bees are flying insects closely related to wasps and ants, known for their role in pollination and, in the case of the best-known bee species, the European honey bee, for producing honey and beeswax. Bees are a monophyletic lineage within the superfamily Apoidea, presently considered as a clade Anthophila. There are nearly 20,000 known species of bees in seven to nine recognized families,[1] though many are undescribed and the actual number is probably higher. They are found on every continent except Antarctica, in every habitat on the planet that contains insect-pollinated flowering plants.EOF";
assert(app.scrollViews.childrenMatchingType(.TextView).element.exists);
}

UI with scrollbar

like image 405
joe Avatar asked Sep 09 '15 07:09

joe


1 Answers

In case anyone else finds this question, I am able to get a UITextView's text by using

app.textViews.element.value as? String

This assumes there's only one text view on the screen at the time.

like image 146
ChrisH Avatar answered Oct 21 '22 13:10

ChrisH