Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCUITest detect UIView

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)?

like image 513
Akram Avatar asked Mar 14 '16 21:03

Akram


2 Answers

Objective-C

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *customView = app.otherElements[@"view_identifier"];

Swift

let app = XCUIApplication()
let customView = app.otherElements["view_identifier"]
like image 172
Akram Avatar answered Sep 17 '22 21:09

Akram


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"] }()
like image 22
Lepidopteron Avatar answered Sep 21 '22 21:09

Lepidopteron