Xcode UI测试-UI测试失败-点击搜索字段“时无法滚动到可见(通过AX操作)”;取消';按钮
我试图通过点击搜索栏中的“取消”按钮来取消搜索字段 测试用例找不到cancel按钮。它在Xcode 7.0.1中运行良好 我添加了谓词以等待按钮出现。当我们点击“取消”按钮时,测试用例失败 日志:Xcode UI测试-UI测试失败-点击搜索字段“时无法滚动到可见(通过AX操作)”;取消';按钮,xcode,xcode7,xcode-ui-testing,Xcode,Xcode7,Xcode Ui Testing,我试图通过点击搜索栏中的“取消”按钮来取消搜索字段 测试用例找不到cancel按钮。它在Xcode 7.0.1中运行良好 我添加了谓词以等待按钮出现。当我们点击“取消”按钮时,测试用例失败 日志: t = 7.21s Tap SearchField t = 7.21s Wait for app to idle t = 7.29s Find the SearchField t = 7.29s S
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
我猜这里的“取消”按钮返回false
用于hittable
属性,这会阻止它点击
如果您在文档中看到tap()
,它会说
/*!
* Sends a tap event to a hittable point computed for the element.
*/
- (void)tap;
似乎XCode 7.1已经破坏了一切。为了让我自己(还有你;)不受这些问题的影响,我在XUIElement
上写了一个扩展,允许点击元素,即使它不可点击。下面的内容可以帮助您
/*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,请使用以下内容:
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()
}
}
}
对我来说,根本原因是我想点击的对象
- 已设置为隐藏(和返回)
- 已移除并重新连接
在这两种情况下,
isAccessibilityElement
属性随后都是false
。将其设置回true
已修复。请检查元素的特性,我在TableViewSectionHeader中遇到了相同的问题,我试图点击,但每次都失败
在我的例子中,它有一个以编程方式添加的UI元素覆盖按钮 如果使用AppCenter模拟器运行测试,应确保在与本地模拟器相同的设备版本上运行测试。我因此失去了三天的工作 这个问题在Google查询中的排名很好,比如“未能滚动到可见(通过AX操作)按钮”。考虑到这个问题的年龄,我倾向于认为这不再是XCUITest框架的问题,正如公认的答案所表明的那样 我发现这个问题是由于
XCElement
存在,但隐藏在软件键盘后面。该错误是由框架发出的,因为它无法将存在的视图滚动到视图中以使其可点击。在我的例子中,有问题的按钮有时在软件键盘后面
我发现iOS模拟器的软件键盘可能在某些情况下关闭(例如:在您的机器上),而在其他情况下打开(例如:在您的CI上)。在我的例子中,我在一台机器上关闭了软件键盘,而在其他机器上默认打开了它
解决方案:在尝试点击键盘后面的按钮之前,关闭键盘。
我发现在点击按钮之前,点击某个地方可以明确地关闭键盘,从而解决了我在所有环境中的问题
我添加了一些操作以使当前响应者辞职FirstResponder。我的文本视图后面的视图将迫使第一响应者辞职,因此我点击最后一个文本区域下方的某个位置
///键盘可能已打开,点击密码字段下方即可将其关闭
设pointBelowPassword=passwordSecureTextField.coordination(带有规格化偏移:CGVector(dx:0.5,dy:1))
按下面的点Password.press(持续时间:0.1)
Sandy的解决方案似乎有一段时间有所帮助,但之后就没有了-然后我将其更改为:
func waitAndForceTap(timeout: UInt32 = 5000) {
XCTAssert(waitForElement(timeout: timeout))
coordinate(withNormalizedOffset: CGVector(dx:0.5, dy:0.5)).tap()
}
主要的一点是,由于问题是isHittable检查引发异常,我根本不进行此检查,在找到元素后直接查找坐标。本着可以覆盖元素的精神,我将RN调试器部分覆盖在我的图标顶部:
@Joe Masilotti有什么想法吗?只是一个精神检查,但是取消按钮是在屏幕上还是需要滚动到?我知道在滚动到元素时仍然存在一些问题。@JoeMasilotti取消按钮在屏幕上。取消按钮是系统默认按钮,它是UISearchbar的一部分。当我点击[self.butions[@“Cancel”]时,它在Xcode 7.0.1中运行良好@Vinpai在点击按钮之前添加
app.tables.cells.allegementsboundbyaccessibilityelement.count
时会发生什么?只是好奇——这有时帮助我“刷新”屏幕。@Konnor,我尝试了你建议的API,但当我点击“取消”按钮时失败了。当我在调试器中查询application.buttons时,它会显示用于修复的cancel ButtonTanks。我在使用cell.tap()时遇到了类似的问题,这就解决了这个问题。Xcode7.1中似乎发生了一些变化,导致某些元素不再可命中我有一个自定义导航栏backButtonItem,在Xcode7.1中它不是可命中的,这个解决方案适合我self.app.navigationBars[“Nav Title”]。StaticText[“custom Back Btn Title”]。ForceTapeElement()
Thank-对我的同一个问题有效。在我的例子中,当点击位于视图中心时,它有效。将偏移更改为(0.5,0.5)<代码>让坐标:xguicoordinate=self.coordinateWithNormalizedOffset(CGVectorMake(0.5,0.5))很棒的工作。在我看到这一切之前,我几乎要把我的macbook弄坏了。这正是我的问题所在。奇怪的是,它开始出现在iOS 11上(在iOS 10上运行良好)。
func waitAndForceTap(timeout: UInt32 = 5000) {
XCTAssert(waitForElement(timeout: timeout))
coordinate(withNormalizedOffset: CGVector(dx:0.5, dy:0.5)).tap()
}