Reputation: 30248
I have a macOS project that I'm creating UI tests for.
While it's relatively easy to find staticText
, buttons
, etc. by their text value. Using a subscript lookup on .textViews
doesn't (seem to) work.
I've managed to get a reference to the NSTextView
I want to inspect using .textViews.firstMatch
but I can't figure out how to assert on it's string value.
I'm looking for something that works like this.
XCTAssertEqual(prefs.textViews.firstMatch.stringValue, "Enter text below")
Upvotes: 0
Views: 526
Reputation: 20234
Simply value
should do.
It's available on XCUIElementAttributes
and is of type Any?
that varies based on the type of the element.
XCTAssertEqual(prefs.textViews.firstMatch.value as! String,
"Enter text below")
Ref:
Upvotes: 2
Reputation: 1523
If you print out the debugDescription
of the element, you should see which parameter holds the value you want to assert equality on. Likely it will be .value
which you can simply coerce into a String for your purposes. Strings adhere to ==
equality checks, making it trivial to compare two strings with just a simple XCTAssert(originalTextViewValue == "String I want to value check against")
Upvotes: 1