【问题标题】:XCUIElementQuery.matching(identifier:) is not working for UIImageViewXCUIElementQuery.matching(identifier:) 不适用于 UIImageView
【发布时间】:2017-10-26 08:56:27
【问题描述】:

我正在尝试实现一个非常简单的测试,但我坚持使用XCUIElementQuery.matching(identifier:) 方法。我认为查询UIImageViews 没有按预期工作,但不知道为什么。

我为视图设置了这两个设置:

  1. 标签:
  2. UIImageView:

我有这个测试:

func testRecording() {
    XCTAssertEqual(app.staticTexts.matching(identifier: "label").count, 2)
    XCTAssertEqual(app.images.matching(identifier: "accept").count, 1)
}

我在哪里查询这两个视图(ID 为 label 的标签和 ID 为 accept 的 UIImageView)。从这里开始:app 被简单地定义为像这样的类属性:let app = XCUIApplication()

所以,这就是屏幕的样子:

这意味着该测试应该通过,因为屏幕上有两个 ID 为 labelstaticTexts 和一个 ID 为 acceptimagestaticTexts 已成功查询,但当 matching(identifier:) 尝试使用 id accept 查询 image 时失败:

我尝试查询很多东西,例如:

  • app.images.
  • app.tables.
  • app.tables.images.
  • app.tables.cells.images.
  • app.buttons.(在辅助功能设置的 Traits 部分中也标记为 Button
  • app.staticTexts.(在辅助功能设置的 Traits 部分中也标记为 Static Text

但没有运气......我在这里做错了什么,或者遗漏了什么吗?

【问题讨论】:

    标签: ios uiimageview swift4 xctestcase xcuitest


    【解决方案1】:

    好的,由于我是 QA 团队的一员,因此我没有过多关注开发代码。但是当我这样做时,我找到了答案。

    用于显示复选标记的 UIImageView 永远不会从 .xib 文件中使用,而是始终分配一个新实例,如下所示:

    indicatorView = UIImageView(image: #imageLiteral(resourceName: "arrow_marked_ok_small"))
    

    意味着新的可访问性选项是通过初始化程序调用设置的,因此具有我在前两个图像中发布的 .xib 文件的可访问性选项的旧 UIImageView 实例将被覆盖。

    【讨论】:

      猜你喜欢
      • 2014-07-29
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      相关资源
      最近更新 更多