【问题标题】:XCUI tests failing on iOS 10 but not iOS 9 due to ""Error -25204 getting snapshot for element"由于“错误 -25204 获取元素快照”,XCUI 测试在 iOS 10 但不是 iOS 9 上失败
【发布时间】:2016-11-29 15:49:30
【问题描述】:

我已经为我的应用程序创建了一个 XCUItesting 测试套件...但是自从升级(不确定是否相关)到 xcode 8 和使用 ios10 模拟器后,我的测试用例将仅在 ios9 中运行,而不是在 10 中运行。当我在 ios 10 模拟器中运行测试时,我收到错误 Assertion Failure: <unknown>:0: UI Testing Failure - Failure getting snapshot Error Domain=XCTestManagerErrorDomain Code=9 "Error -25204 getting snapshot for element <AXUIElement 0x7fe2a6614ad0> {pid=7751}" UserInfo={NSLocalizedDescription=Error -25204 getting snapshot for element <AXUIElement 0x7fe2a6614ad0> {pid=7751}}

有人也遇到过这种情况吗? 或者 有谁知道我哪里出错了?

非常感谢

【问题讨论】:

  • 我遇到了同样的问题。这个有更新吗?

标签: swift xcode ios-simulator xcode-ui-testing


【解决方案1】:

根本原因

我遇到了同样的问题。测试失败并出现同样的错误,但根本原因是应用程序崩溃了。我设置了一个异常断点并将回溯打印出来看看在哪里。

最后,这是uitableviewdelegate的方法签名之一中隐式解包的可选导致的崩溃:

public func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool

UI测试时系统调用该方法,indexPath参数为nil,导致应用挂起。

回溯显示:

(lldb) thread backtrace
* thread #1: tid = 0x128eaa, 0x000000010c776c3a libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 42, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x000000010c776c3a libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 42
    frame #1: 0x0000000108443241 Static`@objc DataSource.tableView(UITableView, canPerformAction : Selector, forRowAt : IndexPath, withSender : Any?) -> Bool + 97 at DataSource.swift:0
    frame #2: 0x00000001095aea31 UIKit`-[UITableView _canPerformAction:forCell:sender:] + 169
    frame #3: 0x00000001098017c6 UIKit`-[UITableViewCell canPerformAction:withSender:] + 86
    frame #4: 0x00000001210a5fc9 UIKit`-[UIResponder(UITextAccessibilityUtilities) _accessibilityHasTextOperations] + 100
    frame #5: 0x000000012107bb7c UIKit`-[UITableViewCellAccessibilityElement _accessibilityHasTextOperations] + 48
    frame #6: 0x00000001211f09ec UIAccessibility`-[NSObject(AXPrivCategory) accessibilityAttributeValue:] + 5945
    frame #7: 0x000000012120bc04 UIAccessibility`_accessibilityAttributesForObject + 767
    frame #8: 0x000000012120b5e8 UIAccessibility`-[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotDescendantsWithAttributes:maxDepth:maxChildren:maxArrayCount:] + 1736
    frame #9: 0x000000012120cf96 UIAccessibility`-[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotWithOptions:] + 557
    frame #10: 0x00000001211eec0a UIAccessibility`-[NSObject(AXPrivCategory) accessibilityAttributeValue:forParameter:] + 7903
    frame #11: 0x00000001211d8856 UIAccessibility`_copyParameterizedAttributeValueCallback + 211
    frame #12: 0x0000000120869532 AXRuntime`_AXXMIGCopyParameterizedAttributeValue + 216
    frame #13: 0x0000000120863f1c AXRuntime`_XCopyParameterizedAttributeValue + 440
    frame #14: 0x0000000120872de5 AXRuntime`mshMIGPerform + 266
    frame #15: 0x00000001064e93d9 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    frame #16: 0x00000001064e9351 CoreFoundation`__CFRunLoopDoSource1 + 465
    frame #17: 0x00000001064e1435 CoreFoundation`__CFRunLoopRun + 2389
    frame #18: 0x00000001064e0884 CoreFoundation`CFRunLoopRunSpecific + 420
    frame #19: 0x000000010e5bda6f GraphicsServices`GSEventRunModal + 161
    frame #20: 0x000000010943dc68 UIKit`UIApplicationMain + 159
    frame #21: 0x000000010462c95f GoOut`main + 111 at AppDelegate.swift:47
    frame #22: 0x000000010cb7e68d libdyld.dylib`start + 1
    frame #23: 0x000000010cb7e68d libdyld.dylib`start + 1

解决方案

在知道是哪种方法导致它之后,修复非常简单——只需将indexPath 类型替换为可选的IndexPath?(添加问号):

public func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath?, withSender sender: Any?) -&gt; Bool

然后使用nil 正确调用该方法并且不会导致崩溃。

有关更多信息,请参阅:https://openradar.appspot.com/31375101 并随意欺骗雷达。

【讨论】:

  • 好东西,很抱歉延迟回复!很高兴你把它解决了!
【解决方案2】:

您使用的是 swift 2 还是 swift 3。我似乎在使用 .hittable (swift 2) 或 .isHittable(swift 3) 检查时经常遇到该错误。看看删除可命中检查是否有帮助。除了内置的可命中检查之外,还有其他选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 2016-10-23
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多