【问题标题】:How to dismiss the UIActivityViewController during a UI test with Xcode 11 & iOS 13如何在使用 Xcode 11 和 iOS 13 进行 UI 测试期间关闭 UIActivityViewController
【发布时间】:2019-10-14 17:37:42
【问题描述】:

Apple 重新设计了显示的共享表,它现在已经破坏了我的 UI 测试。

我试图通过 Xcode 记录一个新的 UI 测试,但只要我点击关闭按钮,测试就会终止,因此我无法捕获事件。

最后,我只想知道如何访问下面箭头所示的灰色“X”:

【问题讨论】:

    标签: ios iphone ios13 uiactivityviewcontroller xcode-ui-testing


    【解决方案1】:

    我刚刚使用 Xcode 13 对此进行了测试,发现原来的答案不再有效。但是,我将它留给后人,或者那些使用以前版本的 Xcode 的人。

    Xcode 13

    我已经使用 Xcode 13.0 对此进行了测试,并验证它适用于 iPhone 和 iPad:

    let activityListView = app.otherElements.element(matching: .other,
                                                     identifier: "ActivityListView")
    XCTAssertTrue(activityListView.waitForExistence(timeout: 2.0))
    activityListView.buttons["Close"].tap()
    

    以前的版本

    经过反复试验,我能够通过以下方式找到我的特定元素所在的位置:

    app.otherElements.element(boundBy: 1).buttons.element(boundBy: 0).tap()

    使用app.otherElements.element(boundBy: 1) 将为我识别共享表。我曾尝试通过可访问性标识符来定位它,但我找不到有效的标识符,包括以前在 iOS 12 及更低版本中使用的有效标识符。

    请注意,根据您的屏幕布局,索引值 可能与我看到的不同。

    接下来,.buttons.element(boundBy: 0).tap() 用于定位 关闭 按钮。我再次尝试使用标识符,但找不到代表按钮的任何内容。

    当我在测试时试图通过控制台识别其他信息时,我总是会导致测试崩溃。这个结果令人惊讶,因为我能够使用 Xcode 10 查询这些元素。

    最终,我想找到有效的标识符值,这样我就可以拥有跨产品可靠工作的东西,而无需反复试验来找到共享表的索引值。

    适用于 iPad

    以下内容将关闭 iPad 的弹出框:

    app.otherElements["PopoverDismissRegion"].tap()
    

    【讨论】:

    • 有更新吗?我得到Failed to synthesize event: Failed to scroll to visible (by AX action) Button, error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 3118, elementOrHash.elementID: 4354340448.106. (Underlying Error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 3118, elementOrHash.elementID: 4354340448.106)
    • @JCutting8 我已经更新了答案,也许这解决了你的问题?
    猜你喜欢
    • 2016-11-21
    • 1970-01-01
    • 2020-01-27
    • 2015-11-04
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    相关资源
    最近更新 更多