Xcode UI测试因存在,isHittable,waitForExistence和记录而崩溃

时间:2019-05-07 21:55:50

标签: ios xcode xcode-ui-testing ui-testing uitest

我有一个非常简单的具有此功能的Xcode UI测试:

func waitForElementToAppear(_ element: XCUIElement) -> Bool {
        let predicate = NSPredicate(format: "exists == true")
        let exp = expectation(for: predicate, evaluatedWith: element, handler: nil)
        let result = XCTWaiter().wait(for: [exp], timeout: 10)
        return result == .completed
}

在Xcode 9之前,我一直为我工作。我不确定这是否是Xcode 10的问题,但是最近它已经开始,而无需我添加或更改任何代码。

这是我的测试代码:

func testTabBarPress() {
        let tabbar = self.app.tabBars["my_tabbar"]
        print(tabbar)
}

此测试成功-始终如此。

func testTabBarPress() {
    let tabbar = self.app.tabBars["my_tabbar"]
    print(tabbar)
    if tabbar.isHittable {  

    }
}

此测试失败-始终如此。它并非仅会失败,它会因Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)而崩溃。

在超过99.945秒后,它从崩溃状态切换为失败测试状态,并显示消息:Timeout waiting for fulfillment of promise for 'remote query'.

该测试:

func testTabBarPress() {
    let tabbar = self.app.tabBars["my_tabbar"]
    print(tabbar)
    if waitForElementToAppear(tabbar) {

    }
}

以相同的消息EXC_BAD_ACCESS崩溃,但此后确实成功。

我也确实重置了模拟器,清理了构建文件夹并将Xcode更新为10.2.1(10E1001)

在测试的顶部,我定义了我的应用程序:

private var app: XCUIApplication = XCUIApplication(),然后在setup()中启动它。

任何帮助表示赞赏。谢谢!

编辑:

这是堆栈跟踪:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000113a833d0 libsystem_platform.dylib`_platform_strcmp + 80
    frame #1: 0x00000001322086f1 UIKit`-[UIViewAccessibility _accessibilityRetrieveIvarText] + 364
    frame #2: 0x00000001321f5e54 UIKit`-[UITableViewCellAccessibility _accessibilityRetrieveTableViewIvarsText] + 118
    frame #3: 0x00000001321f6b27 UIKit`-[UITableViewCellAccessibility _accessibilityRetrieveTableViewCellText:] + 2749
    frame #4: 0x00000001321f99c1 UIKit`-[UITableViewCellAccessibility accessibilityLabel] + 123
    frame #5: 0x000000012ee47739 PreferencesFramework`-[UITableViewCellAccessibility__Preferences__UIKit accessibilityLabel] + 327
    frame #6: 0x000000013243f31c UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityPotentiallyAttributedValueForNonAttributedSelector:attributedSelector:] + 244
    frame #7: 0x000000013243f478 UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityAXAttributedLabel] + 41
    frame #8: 0x00000001321d620e UIKit`-[UINavigationBarAccessibility_UIViewAccessibilityAdditions _accessibilityAXAttributedLabel] + 650
    frame #9: 0x000000013220b711 UIKit`-[UITableViewCellAccessibilityElement accessibilityLabel] + 48
    frame #10: 0x000000013243f31c UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityPotentiallyAttributedValueForNonAttributedSelector:attributedSelector:] + 244
    frame #11: 0x000000013243f478 UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityAXAttributedLabel] + 41
    frame #12: 0x000000013243e9ae UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityProcessedLabelAttribute] + 34
    frame #13: 0x0000000132442c32 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityAttributeValue:] + 268
    frame #14: 0x000000013246cacd UIAccessibility`_accessibilityAttributesForObject + 493
    frame #15: 0x000000013246c43a UIAccessibility`-[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotDescendantsWithAttributes:maxDepth:maxChildren:maxArrayCount:] + 1239
    frame #16: 0x000000013246dfd9 UIAccessibility`-[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotWithOptions:] + 1139
    frame #17: 0x0000000132441f09 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityAttributeValue:forParameter:] + 8537
    frame #18: 0x00000001321cb100 UIKit`-[UIApplicationAccessibility accessibilityAttributeValue:forParameter:] + 290
    frame #19: 0x0000000132424657 UIAccessibility`_copyParameterizedAttributeValueCallback + 434
    frame #20: 0x0000000130ef1629 AXRuntime`___AXXMIGCopyParameterizedAttributeValue_block_invoke + 50
    frame #21: 0x0000000130ef0f99 AXRuntime`_handleNonMainThreadCallback + 55
    frame #22: 0x0000000130ef14cb AXRuntime`_AXXMIGCopyParameterizedAttributeValue + 285
    frame #23: 0x0000000130eec976 AXRuntime`AXUIElementCopyParameterizedAttributeValue + 495
    frame #24: 0x0000000130e80351 XCTAutomationSupport`-[XCTAccessibilityFramework userTestingSnapshotForElement:options:error:] + 420
    frame #25: 0x0000000130e77e90 XCTAutomationSupport`-[XCTElementSnapshotRequest(PlatformImplementation) accessibilitySnapshotOrError:] + 1263
    frame #26: 0x0000000130e8305f XCTAutomationSupport`__56-[XCTElementSnapshotRequest loadSnapshotAndReturnError:]_block_invoke_2 + 64
    frame #27: 0x0000000130e728dd XCTAutomationSupport`__XCTPerformOnMainRunLoop_block_invoke + 295
    frame #28: 0x0000000111251aec CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #29: 0x00000001112512b0 CoreFoundation`__CFRunLoopDoBlocks + 336
    frame #30: 0x000000011124c10b CoreFoundation`__CFRunLoopRun + 2747
    frame #31: 0x000000011124b302 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #32: 0x000000011748d2fe GraphicsServices`GSEventRunModal + 65
    frame #33: 0x0000000119ea2ba2 UIKitCore`UIApplicationMain + 140
  * frame #34: 0x000000010d2afa4b Musify`main at AppDelegate.swift:20:7
    frame #35: 0x0000000113721541 libdyld.dylib`start + 1
    frame #36: 0x0000000113721541 libdyld.dylib`start + 1

这是录音崩溃的痕迹:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000107c223d0 libsystem_platform.dylib`_platform_strcmp + 80
    frame #1: 0x00000001269186f1 UIKit`-[UIViewAccessibility _accessibilityRetrieveIvarText] + 364
    frame #2: 0x0000000126905e54 UIKit`-[UITableViewCellAccessibility _accessibilityRetrieveTableViewIvarsText] + 118
    frame #3: 0x0000000126906b27 UIKit`-[UITableViewCellAccessibility _accessibilityRetrieveTableViewCellText:] + 2749
    frame #4: 0x00000001269099c1 UIKit`-[UITableViewCellAccessibility accessibilityLabel] + 123
    frame #5: 0x0000000123633739 PreferencesFramework`-[UITableViewCellAccessibility__Preferences__UIKit accessibilityLabel] + 327
    frame #6: 0x0000000126b4f31c UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityPotentiallyAttributedValueForNonAttributedSelector:attributedSelector:] + 244
    frame #7: 0x0000000126b4f478 UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityAXAttributedLabel] + 41
    frame #8: 0x00000001268e620e UIKit`-[UINavigationBarAccessibility_UIViewAccessibilityAdditions _accessibilityAXAttributedLabel] + 650
    frame #9: 0x000000012691b711 UIKit`-[UITableViewCellAccessibilityElement accessibilityLabel] + 48
    frame #10: 0x0000000126b4f31c UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityPotentiallyAttributedValueForNonAttributedSelector:attributedSelector:] + 244
    frame #11: 0x0000000126b4f478 UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityAXAttributedLabel] + 41
    frame #12: 0x0000000126b4e9ae UIAccessibility`-[NSObject(AXPrivCategory) _accessibilityProcessedLabelAttribute] + 34
    frame #13: 0x0000000126b52c32 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityAttributeValue:] + 268
    frame #14: 0x0000000126b7cacd UIAccessibility`_accessibilityAttributesForObject + 493
    frame #15: 0x0000000126b7c43a UIAccessibility`-[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotDescendantsWithAttributes:maxDepth:maxChildren:maxArrayCount:] + 1239
    frame #16: 0x0000000126b7dfd9 UIAccessibility`-[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotWithOptions:] + 1139
    frame #17: 0x0000000126b51f09 UIAccessibility`-[NSObject(AXPrivCategory) accessibilityAttributeValue:forParameter:] + 8537
    frame #18: 0x00000001268db100 UIKit`-[UIApplicationAccessibility accessibilityAttributeValue:forParameter:] + 290
    frame #19: 0x0000000126b34657 UIAccessibility`_copyParameterizedAttributeValueCallback + 434
    frame #20: 0x00000001260bf629 AXRuntime`___AXXMIGCopyParameterizedAttributeValue_block_invoke + 50
    frame #21: 0x00000001260bef99 AXRuntime`_handleNonMainThreadCallback + 55
    frame #22: 0x00000001260bf4cb AXRuntime`_AXXMIGCopyParameterizedAttributeValue + 285
    frame #23: 0x00000001260b94f0 AXRuntime`_XCopyParameterizedAttributeValue + 414
    frame #24: 0x00000001260ce1b7 AXRuntime`mshMIGPerform + 237
    frame #25: 0x00000001053ea419 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    frame #26: 0x00000001053e9a7b CoreFoundation`__CFRunLoopDoSource1 + 459
    frame #27: 0x00000001053e400a CoreFoundation`__CFRunLoopRun + 2490
    frame #28: 0x00000001053e3302 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #29: 0x000000010b62c2fe GraphicsServices`GSEventRunModal + 65
    frame #30: 0x000000010e822ba2 UIKitCore`UIApplicationMain + 140
  * frame #31: 0x00000001013dea4b Musify`main at AppDelegate.swift:20:7
    frame #32: 0x00000001078c0541 libdyld.dylib`start + 1
    frame #33: 0x00000001078c0541 libdyld.dylib`start + 1

顺便说一句,录制和点击元素也会崩溃。

编辑2:

我发现使用Accessibility Identifier也会使应用程序崩溃。因此,我只需要将鼠标悬停在Simulator上即可使应用程序崩溃。我没有主意:(

0 个答案:

没有答案