Xcode UI 测试 - UI 测试失败 - 点击搜索字段“取消"按钮时无法滚动到可见(通过 AX 操作) [英] Xcode UI test - UI Testing Failure - Failed to scroll to visible (by AX action) when tap on Search field "Cancel' button
问题描述
我试图通过点击搜索栏中的取消"按钮来关闭搜索字段.
I am trying to dismiss the search field by tapping 'Cancel' button in search bar.
测试用例找不到取消按钮.它在 Xcode 7.0.1 中运行良好
The test case is failing to find the cancel button. It was working fine in Xcode 7.0.1
我添加了谓词以等待按钮出现.当我们点击取消"按钮时,测试用例失败
I have added predicate to wait for button to appear. The test case is failing when we tap of "cancel" button
let button = app.buttons["Cancel"]
let existsPredicate = NSPredicate(format: "exists == 1")
expectationForPredicate(existsPredicate, evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)
button.tap() // Failing here
日志:
t = 7.21s Tap SearchField
t = 7.21s Wait for app to idle
t = 7.29s Find the SearchField
t = 7.29s Snapshot accessibility hierarchy for com.test.mail
t = 7.49s Find: Descendants matching type SearchField
t = 7.49s Find: Element at index 0
t = 7.49s Wait for app to idle
t = 7.55s Synthesize event
t = 7.84s Wait for app to idle
t = 8.97s Type 'vinayak@xmd.net' into
t = 8.97s Wait for app to idle
t = 9.03s Find the "Search" SearchField
t = 9.03s Snapshot accessibility hierarchy for com.test.mail
t = 9.35s Find: Descendants matching type SearchField
t = 9.35s Find: Element at index 0
t = 9.36s Wait for app to idle
t = 9.42s Synthesize event
t = 10.37s Wait for app to idle
t = 10.44s Check predicate `exists == 1` against object `"Cancel" Button`
t = 10.44s Snapshot accessibility hierarchy for com.test.mail
t = 10.58s Find: Descendants matching type Button
t = 10.58s Find: Elements matching predicate '"Cancel" IN identifiers'
t = 10.58s Tap "Cancel" Button
t = 10.58s Wait for app to idle
t = 10.64s Find the "Cancel" Button
t = 10.64s Snapshot accessibility hierarchy for com.test.mail
t = 10.78s Find: Descendants matching type Button
t = 10.78s Find: Elements matching predicate '"Cancel" IN identifiers'
t = 10.79s Wait for app to idle
t = 11.08s Synthesize event
t = 11.13s Scroll element to visible
t = 11.14s Assertion Failure: UI Testing Failure - Failed to scroll to visible (by AX action) Button 0x7f7fcaebde40: traits: 8589934593, {{353.0, 26.0}, {53.0, 30.0}}, label: 'Cancel', error: Error -25204 performing AXAction 2003
推荐答案
我猜这里的取消"按钮为 hittable
属性返回 false
,这是阻止它点击.
I guess here "Cancel" button returns false
for hittable
property, that is preventing it from tapping.
如果你在文档中看到 tap()
它说
If you see tap()
in documentation it says
/*!
* Sends a tap event to a hittable point computed for the element.
*/
- (void)tap;
XCode 7.1 似乎坏了.以下内容可以帮助您.
It seems things are broken with XCode 7.1.To keep myself (and u too ;)) unblocked from these issues I wrote a extension on XCUIElement
that allows tap on element even if it is not hittable. Following can help you.
/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
func forceTapElement() {
if self.hittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
coordinate.tap()
}
}
}
现在你可以调用了
button.forceTapElement()
更新 - 对于 swift 3 使用以下内容:
Update - For swift 3 use following:
extension XCUIElement {
func forceTapElement() {
if self.isHittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx:0.0, dy:0.0))
coordinate.tap()
}
}
}
这篇关于Xcode UI 测试 - UI 测试失败 - 点击搜索字段“取消"按钮时无法滚动到可见(通过 AX 操作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!