Reputation: 1941
I have a banner kind UIView
, which appears and disappear after certain amount of time on tap of a button action. This is being presented on a UIWindow
level. I want to access this banner UIView
and UILabel
inside the view, for automating the testcase in XCode UITesting. How to achieve this? Thanks in advance!
Upvotes: 0
Views: 852
Reputation: 17008
It shouldn't matter where the banner exists in the app's view hierarchy. UI Testing just uses accessibility to find elements. As long as there is a valid accessibilityIdentifier
set on the banner you can find it via a simple query.
Since there is a UILabel
inside try finding the banner via that. This checks if the label is in he view hierarchy.
XCTAssert(app.staticTexts["Banner Text"].exists)
If the view isn't removed but just set to hidden, you will want to use hittable
over exists
. This will make sure that the element is not only visible, but also not hidden
.
XCTAssert(app.staticTexts["Banner Text"].hittable)
Upvotes: 1