【问题标题】:XCUITest detect UIViewXCUITest 检测 UIView
【发布时间】:2016-03-14 21:32:02
【问题描述】:
所以在 XCUITest 中我使用这段代码来获取一个按钮:
XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *button = app.buttons[@"button_identifier"];
使用app.tables 获取tableview,使用app.images 获取图像等等。
但是我怎样才能得到一个视图(UIView)?
【问题讨论】:
标签:
xcode
uiview
automated-tests
xctest
【解决方案1】:
Objective-C
XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *customView = app.otherElements[@"view_identifier"];
斯威夫特
let app = XCUIApplication()
let customView = app.otherElements["view_identifier"]
【解决方案2】:
对于 Swift 3 / 4,它看起来像:
let app = XCUIApplication()
let custom_view = app.otherElements["view_identifier"]
另外我喜欢做的是有一个类变量,因为我经常将这些视图重用于不同的测试:
lazy var custom_view: XCUIElement = { return XCUIApplication().otherElements["view_identifier"] }()