car*_*onr 9 ios swift xcode7 xcode-ui-testing
在我的项目上使用 Xcode 开始 UI 测试,遇到了障碍。
有一个UITextField调用的子类,RSCustomTextField它有一些 UI 自定义。添加到RSSearchHeadView包含文本字段和按钮的 。
所以我无法查询文本字段,app.textfields["Search field"]因为它是一个自定义类,它显示为app.otherElements["Search field"]
它在searchField.typeText("abc")显示错误时崩溃元素和任何后代都没有键盘焦点。.
即使在tap()元素之后。请注意,我还尝试在子类和文本字段上设置可访问性特征,UIAccessibilityTraitSearchField但没有区别。
func testSearchIcon() {
let searchField = app.otherElements["Search field"]
searchField.tap()
searchField.typeText("abc")
app.keys["delete"].tap()
XCTAssertFalse(searchDubizzleElement.hittable)
}
Run Code Online (Sandbox Code Playgroud)
debugDescription在应用程序上打印提供以下输出:
Element subtree:
?Application 0x7fc1b3f3aa00: {{0.0, 0.0}, {375.0, 667.0}}, label: 'myappname-masked'
Window 0x7fc1b3f439b0: Main Window, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f55c20: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f43440: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f31830: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f61ff0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f52820: traits: 8589934592, {{0.0, 0.0}, {375.0, 64.0}}
Other 0x7fc1b3f4e190: traits: 8589934592, {{0.0, 0.0}, {375.0, 64.0}}
Button 0x7fc1b3f3a250: traits: 8589934593, {{5.0, 20.0}, {44.0, 44.0}}, label: 'search icon right'
Other 0x7fc1b3f349b0: traits: 8589935616, {{15.0, 20.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, 20.0}, {44.0, 44.0}}, label: 'your account icon'
CollectionView 0x7fc1b3f32450: traits: 35192962023424, {{0.0, 64.0}, {375.0, 603.0}}
Cell 0x7fc1b3f1e230: traits: 8589934592, {{0.0, 64.0}, {375.0, 50.0}}
......
Run Code Online (Sandbox Code Playgroud)
小智 0
我在 UITextField 的自定义子类中遇到了同样的错误。问题的根源在于leftView在 UITextField 上以编程方式插入 a 。使用这些子视图属性会扰乱自动化 UI 测试的可访问性。
为了解决这个问题,我避免在 UITextFields 上使用leftView或。rightView相反,我通过修改textRect此处答案之一(目前是第二高票数)中描述的方法来实现所需的缩进:Set padding for UITextField with UITextBorderStyleNone
我无法从您的代码中判断您的问题是否相同,但我想我会分享这个小发现。