【问题标题】:Is it possible to get an `XCUIElement` by its `accessibilityId` when it is not an accessibility element?当它不是可访问性元素时,是否可以通过其 `accessibilityId` 获取`XCUIElement`?
【发布时间】:2020-08-20 18:57:58
【问题描述】:

我有自定义UITableViewCell 带有一些子图像和标签。我已将整个单元格作为一个可访问的元素。我已经为所有元素设置了可访问性 ID - 单元格及其子视图,希望能够在 XCUITests 中使用它。

现在,我无法使用XCUIApplication().images["cell_image_acc_id"] 获取图像。

我应该怎么做才能获得这些元素?我是 XC ui 测试的新手。如果我缺少一些基本的东西,请告诉我。

提前致谢。

【问题讨论】:

    标签: ios swift accessibility xcuitest


    【解决方案1】:

    如果您将视图设置为可访问性元素,则其子视图对 VoiceOver 用户不可用,因此无法测试。虽然它对可访问性用户有好处,但可能会影响可测试性。

    您可以在测试时为您的应用传递环境变量或启动参数。如果设置了此类变量(或参数),请不要在您的应用代码中设置 isAccessibilityElementhttps://developer.apple.com/documentation/objectivec/nsobject/1615141-isaccessibilityelement https://developer.apple.com/documentation/xctest/xcuiapplication/1500477-launcharguments https://developer.apple.com/documentation/xctest/xcuiapplication/1500427-launchenvironment How to detect if iOS app is running in UI Testing mode

    这样,您仍然可以为 VoiceOver 用户提供出色的体验并正确测试您的代码。

    【讨论】:

      猜你喜欢
      • 2011-07-11
      • 2013-06-26
      • 2013-05-14
      • 2011-11-19
      • 1970-01-01
      • 2017-05-17
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多