So in XCUITest I use this code to get a button:
XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *button = app.buttons[@"button_identifier"];
getting a tableview using app.tables
and image using app.images
and so on.
But how can I get a view(UIView)?
Objective-C
XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *customView = app.otherElements[@"view_identifier"];
Swift
let app = XCUIApplication()
let customView = app.otherElements["view_identifier"]
For Swift 3 / 4 it would look like:
let app = XCUIApplication()
let custom_view = app.otherElements["view_identifier"]
Also what I like to do is to have a class variable, as I do reuse these views frequently for different tests:
lazy var custom_view: XCUIElement = { return XCUIApplication().otherElements["view_identifier"] }()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With