【问题标题】:iOS UI testing - presented view controller appearing as "other element"iOS UI 测试 - 呈现的视图控制器显示为“其他元素”
【发布时间】:2017-03-21 20:51:33
【问题描述】:

我正在尝试为我的应用编写 UI 测试。我有一个弹出窗口,它是一个模态呈现的视图控制器,上面有一个 UITableView。 tableview 包含 2 个可点击的单元格,这两个单元格都关闭了视图控制器。问题是当这个弹出窗口出现时,它在我的元素树中显示为“其他元素”,而不是视图控制器。我可以找到带有otherElements[@"PopOverViewController"] 的元素,但我无法单击控制器上的单元格,因为它不知道它们是什么。

 →Other 0x7fc778039540: traits: 8589934592, {{32.0, 155.5}, {311.0, 356.0}}, label: 'PopOverViewController'

如何访问该元素并单击该视图控制器上的按钮?

谢谢

编辑

这是显示 PopOverViewController 时的输出

  Image 0x7fc26378c270: traits: 8589934596
  Image 0x7fc263784310: traits: 8589934596, {{0.0, 0.0}, {375.0, 64.0}}
  Button 0x7fc263786ff0: traits: 8724152321, {{8.0, 26.0}, {110.0, 30.0}}, label: '*****'
  Button 0x7fc26378d480: traits: 8724152321, {{8.0, 36.5}, {11.0, 11.0}}, label: '*****'
  StaticText 0x7fc263794620: traits: 8589934656
  StaticText 0x7fc2637817d0: traits: 8590000192
  NavigationBar 0x7fc263788140: traits: 35192962023424, {{0.0, 20.0}, {375.0, 44.0}}, identifier: '*****'
  StaticText 0x7fc263793090: traits: 8589934656, {{146.5, 70.5}, {82.0, 22.0}}, label: '*****'
  Button 0x7fc26378ea40: traits: 8589934593, {{67.5, 104.5}, {240.0, 35.0}}, label: '*****'
  StaticText 0x7fc26378de50: traits: 8589934656, {{86.0, 155.5}, {203.5, 38.5}}, label: '*****'
  Other 0x7fc263795f30: traits: 8589934592, {{67.5, 54.0}, {240.0, 168.0}}
  Other 0x7fc26379b470: traits: 8589934592
  Other 0x7fc26379a570: traits: 8589934592, {{0.0, 64.0}, {375.0, 148.0}}
  Other 0x7fc26378f9c0: traits: 8589934592, {{0.0, 216.0}, {375.0, 407.0}}
  StaticText 0x7fc26379be90: traits: 8589934656, {{90.0, 232.0}, {53.5, 20.5}}, label: '*****'
  StaticText 0x7fc26379c4f0: traits: 8589934656, {{90.0, 250.0}, {114.0, 19.5}}, label: '*****'
  StaticText 0x7fc26379cd60: traits: 8589934656, {{90.0, 289.0}, {57.0, 18.0}}, label: '*****'
  Cell 0x7fc2637934c0: traits: 8589934592, {{0.0, 216.0}, {375.0, 123.0}}
  StaticText 0x7fc26379dc10: traits: 8589934656, {{90.0, 355.0}, {52.5, 20.5}}, label: '*****'
  StaticText 0x7fc26379e330: traits: 8589934656, {{90.0, 373.0}, {98.0, 19.5}}, label: '*****'
  StaticText 0x7fc26379ea80: traits: 8589934656, {{90.0, 412.0}, {57.0, 18.0}}, label: '*****'
  Cell 0x7fc26379d490: traits: 8589934592, {{0.0, 339.0}, {375.0, 123.0}}
  StaticText 0x7fc26379f970: traits: 8589934656, {{90.0, 478.0}, {95.0, 20.5}}, label: '*****'
  StaticText 0x7fc2637a00b0: traits: 8589934656, {{90.0, 496.0}, {129.5, 19.5}}, label: '*****'
  StaticText 0x7fc2637a0800: traits: 8589934656, {{90.0, 535.0}, {57.0, 18.0}}, label: '*****'
  Cell 0x7fc26379f1f0: traits: 8589934592, {{0.0, 462.0}, {375.0, 123.0}}
  Table 0x7fc2637901b0: traits: 35192962023424, {{0.0, 64.0}, {375.0, 559.0}}
  Button 0x7fc2637a0ff0: traits: 8589934593, {{0.0, 623.0}, {375.0, 44.0}}, label: '*****'
  Other 0x7fc2637a1710: traits: 8589934592
  Other 0x7fc263796ea0: traits: 8589934592, {{0.0, 64.0}, {375.0, 603.0}}
  Other 0x7fc263799490: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc263791ac0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc26376a060: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Image 0x7fc2637a26a0: traits: 4, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a2de0: {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a3500: traits: 8589934592, {{32.0, 155.5}, {311.0, 356.0}}, label: 'PopOverViewController'
  Other 0x7fc2637a1f50: {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc263782e40: {{0.0, 0.0}, {375.0, 667.0}}
  Window 0x7fc263112950: Main Window, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a4cc0: traits: 8589934592
  Other 0x7fc2637a44d0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Window 0x7fc2637a3d50: {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a6340: {{0.0, 0.0}, {375.0, 20.0}}
  Other 0x7fc2637a7210: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
  Other 0x7fc2637a7960: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
  Other 0x7fc2637a80e0: traits: 8389120, {{165.0, 0.0}, {48.0, 20.0}}, label: '1:29 PM'
  Other 0x7fc2637a8850: traits: 8388608, {{345.0, 0.0}, {25.0, 20.0}}, label: '-100% battery power'
  Other 0x7fc2637a6a90: {{0.0, 0.0}, {375.0, 20.0}}
  StatusBar 0x7fc2637a5bd0: {{0.0, 0.0}, {375.0, 20.0}}
  Window 0x7fc2637a5450: {{0.0, 0.0}, {375.0, 667.0}}

我可以看到 PopOverViewController,但上面没有任何文本或单元格(文本是空白的,但来自呈现视图控制器,而不是弹出视图控制器上的内容)

编辑

如果我运行[app.otherElements[@"PopOverViewController"] descendantsMatchingType:XCUIElementTypeAny],我会看到输出:

Other 0x7fc263795f30: traits: 8589934592, {{67.5, 54.0}, {240.0, 168.0}}
  Other 0x7fc26379b470: traits: 8589934592
  Other 0x7fc26379a570: traits: 8589934592, {{0.0, 64.0}, {375.0, 148.0}}
  Other 0x7fc26378f9c0: traits: 8589934592, {{0.0, 216.0}, {375.0, 407.0}}
  Other 0x7fc2637a1710: traits: 8589934592
  Other 0x7fc263796ea0: traits: 8589934592, {{0.0, 64.0}, {375.0, 603.0}}
  Other 0x7fc263799490: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc263791ac0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc26376a060: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a2de0: {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a3500: traits: 8589934592, {{32.0, 155.5}, {311.0, 356.0}}, label: 'PopOverViewController'
  Other 0x7fc2637a1f50: {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc263782e40: {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a4cc0: traits: 8589934592
  Other 0x7fc2637a44d0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fc2637a6340: {{0.0, 0.0}, {375.0, 20.0}}
  Other 0x7fc2637a7210: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
  Other 0x7fc2637a7960: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
  Other 0x7fc2637a80e0: traits: 8389120, {{165.0, 0.0}, {48.0, 20.0}}, label: '1:29 PM'
  Other 0x7fc2637a8850: traits: 8388608, {{345.0, 0.0}, {25.0, 20.0}}, label: '-100% battery power'
  Other 0x7fc2637a6a90: {{0.0, 0.0}, {375.0, 20.0}}

这可能是我展示的视图控制器,但我看不到任何对象是什么,因为它们都是“其他”

【问题讨论】:

    标签: ios objective-c xcode-ui-testing ui-testing


    【解决方案1】:

    尝试直接按内容访问单元格。

    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app.staticTexts[@"Cell One"] tap];
    

    【讨论】:

    • 已经尝试过了,但没有帮助。通过元素检查器查看时,尽管 2 按钮上的文本在屏幕上,但它们并没有出现。我没有对视图控制器做任何特别的事情,它是一个带有自定义转换的非全屏模式。
    【解决方案2】:

    容器视图中的元素通常是不可访问的。使 PopOverViewController 不可访问,并且单元格应该可用。

    self.isAccessibilityElement = false
    

    在视图控制器上执行此操作,然后像往常一样查询单元格。

    app.cells.elementBoundByIndex(0).tap()
    

    【讨论】:

    • 感谢您的回复。我试过这个也无济于事。我在显示弹出窗口之前和之后从元素树中获取了打印输出并且它没有改变,新元素只是没有出现在元素树中。
    • @IanYakHoughton 您能否在弹出窗口之前和之后为您的app.descendantsMatchingType(.Any).debugDescription 问题添加输出?
    • 我已将输出添加到我的原始问题中,其中文本被空白。我可以看到“PopOverViewController”,但没有任何关联。
    【解决方案3】:

    我设法通过删除情节提要上启用的可访问性标志来解决此问题。在此之后,单元格在元素检查器中变得可见。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 2021-06-18
      相关资源
      最近更新 更多