在我的项目中使用
Xcode开始UI测试,遇到障碍.
UITextField的子类名为RSCustomTextField,它有一些UI自定义.这是添加到RSSearchHeadView,其中包含文本字段和按钮.
所以我无法将文本字段查询为app.textfields [“搜索字段”],因为它是一个自定义类,它显示为app.otherElements [“搜索字段”]
它在searchField.typeText(“abc”)上崩溃,显示错误.无论是元素还是任何后代都没有键盘焦点.
甚至在元素上点击()之后.注意,我也尝试在子类和文本字段上设置辅助功能特性为UIAccessibilityTraitSearchField但没有区别.
func testSearchIcon() { let searchField = app.otherElements["Search field"] searchField.tap() searchField.typeText("abc") app.keys["delete"].tap() XCTAssertFalse(searchDubizzleElement.hittable) }
在app上打印debugDescription会提供以下输出:
Element subtree: →Application 0x7fc1b3f3aa00: {{0.0,0.0},{375.0,667.0}},label: 'myappname-masked' Window 0x7fc1b3f439b0: Main Window,{{0.0,667.0}} Other 0x7fc1b3f55c20: traits: 8589934592,667.0}} Other 0x7fc1b3f43440: traits: 8589934592,667.0}} Other 0x7fc1b3f31830: traits: 8589934592,667.0}} Other 0x7fc1b3f61ff0: traits: 8589934592,667.0}} Other 0x7fc1b3f52820: traits: 8589934592,64.0}} Other 0x7fc1b3f4e190: traits: 8589934592,64.0}} Button 0x7fc1b3f3a250: traits: 8589934593,{{5.0,20.0},{44.0,44.0}},label: 'search icon right' Other 0x7fc1b3f349b0: traits: 8589935616,{{15.0,{345.0,39.0}},label: 'Search field' Image 0x7fc1b3f3b3b0: traits: 8589934596,{{139.0,22.0},{97.0,30.0}},identifier: 'logo' Button 0x7fc1b3f537a0: traits: 8589934593,{{326.0,label: 'your account icon' CollectionView 0x7fc1b3f32450: traits: 35192962023424,64.0},603.0}} Cell 0x7fc1b3f1e230: traits: 8589934592,50.0}} ......