2

在 UI 测试 (XCUITestCase) 中,当我尝试让测试点击 anMDCMultilineTextField时,测试失败并显示

元素和任何后代都没有键盘焦点。

如果我尝试使用 UI 测试记录器并点击MDCMultilineTextField它无法找到带有错误的多行文本字段:

时间戳事件匹配错误:未能找到匹配元素

我的测试用例

let descField = app.otherElements["EventEditor-TextField-Desc"]
let exp = expectation(for: NSPredicate(format: "exists == true"), evaluatedWith: descField, handler: nil)
XCTWaiter().wait(for: [exp], timeout: timeout)
descField.tap()
descField.typeText("Desc 4")
let saveButton = app.buttons["EventEditor-Button-Submit"]
saveButton.tap()

,其中EventEditor-TextField-Desc是分配给 的可访问性标识符MDCMultilineTextField

运行测试时,它无法告知Neither element nor any descendant has keyboard focus.并将该行标记descField.typeText("Desc 4")为有错误。详细错误描述:

Neither element nor any descendant has keyboard focus. Event dispatch snapshot: Other, identifier: 'EventEditor-TextField-Desc', value: Description
Element debug description:
Attributes: Other, {{177.0, 162.0}, {382.0, 78.0}}, identifier: 'EventEditor-TextField-Desc', value: Description
Element subtree:
 →Other, 0x6000020a7a80, {{177.0, 162.0}, {382.0, 78.0}}, identifier: 'EventEditor-TextField-Desc', value: Description
Path to element:
 →Application, pid: 61807, label: 'R+F Virtual Live'
  ↳Window (Main), {{0.0, 0.0}, {736.0, 414.0}}
   ↳Other, {{0.0, 0.0}, {736.0, 414.0}}
    ↳Other, {{161.0, 20.0}, {414.0, 394.0}}
     ↳Other, {{161.0, 20.0}, {414.0, 394.0}}
      ↳Other, {{161.0, 20.0}, {414.0, 394.0}}
       ↳Other, {{161.0, 20.0}, {414.0, 394.0}}
        ↳Other, {{161.0, 64.0}, {414.0, 350.0}}
         ↳ScrollView, {{161.0, 64.0}, {414.0, 350.0}}
          ↳Other, {{161.0, 64.0}, {414.0, 350.0}}
           ↳Other, {{177.0, 84.0}, {382.0, 282.0}}
            ↳Other, {{177.0, 162.0}, {382.0, 78.0}}, identifier: 'EventEditor-TextField-Desc', value: Description
Query chain:
 →Find: Target Application 'com.abc.myApp'
  Output: {
    Application, pid: 61807, label: 'MyApp'
  }
  ↪︎Find: Descendants matching type Other
    Output: {
      Other, {{0.0, 0.0}, {736.0, 414.0}}
      Other, {{0.0, 0.0}, {736.0, 414.0}}
      Other, {{0.0, 0.0}, {736.0, 414.0}}
      Other, {{-0.0, -0.0}, {414.0, 736.0}}
      Other, {{0.0, 0.0}, {736.0, 414.0}}
      Other, {{0.0, 0.0}, {736.0, 414.0}}
      Other, {{161.0, 20.0}, {414.0, 394.0}}
      Other, {{0.0, 370.0}, {736.0, 44.0}}
      Other, {{370.0, -0.0}, {206.0, 736.0}}
      Other, {{0.0, 0.0}, {320.0, 414.0}}
      Other, {{320.3, 0.0}, {415.7, 414.0}}
      Other, {{161.0, 20.0}, {414.0, 394.0}}
      Other, {{370.0, -0.0}, {44.0, 736.0}}
      Other, {{414.0, -0.0}, {162.0, 736.0}}
      Other, {{414.0, -0.0}, {162.0, 736.0}}
      Other, {{0.0, 0.0}, {320.0, 414.0}}
      Other, {{320.3, 0.0}, {415.7, 414.0}}
      Other, {{161.0, 20.0}, {414.0, 394.0}}
      Other, {{0.0, 370.0}, {736.0, 44.0}}
      Other, {{414.0, -0.0}, {162.0, 736.0}}
      Other, {{0.0, 0.0}, {320.0, 414.0}}
      Other, {{320.3, 0.0}, {415.7, 414.0}}
      Other, {{316.7, 35.7}, {103.0, 17.0}}, label: 'NEW EVENT'
      Other, {{161.0, 20.0}, {414.0, 394.0}}
      Other, {{0.0, 370.0}, {736.0, 44.0}}
      Other, {{414.0, -0.0}, {162.0, 736.0}}
      Other, {{414.0, -0.0}, {162.0, 736.0}}
      Other, {{0.0, 0.0}, {320.0, 414.0}}
      Other, {{320.3, 44.0}, {415.7, 370.0}}
      Other, {{161.0, 64.0}, {414.0, 350.0}}
      Other, {{353.0, 378.0}, {30.0, 28.0}}, label: 'Toolbar Title Button'
      Other, {{414.0, -0.0}, {162.0, 736.0}}
      Other, {{414.0, -0.0}, {162.0, 736.0}}
      Other, {{0.0, 0.0}, {320.0, 414.0}}
      Other, {{320.3, 44.0}, {415.7, 370.0}}
      Other, {{111.0, 15.7}, {98.3, 17.0}}, label: 'MY EVENTS'
      Other, {{0.0, 0.0}, {320.0, 414.0}}
      Other, {{320.3, 44.0}, {415.7, 370.0}}
      Other, {{161.0, 64.0}, {414.0, 350.0}}
      Other, {{0.0, 44.0}, {320.0, 321.0}}
      Other, {{177.0, 84.0}, {382.0, 282.0}}
      Other, {{320.3, 44.0}, {415.7, 585.0}}
      Other, {{177.0, 162.0}, {382.0, 78.0}}, identifier: 'EventEditor-TextField-Desc', value: Description
      Other, {{177.0, 240.0}, {382.0, 58.0}}
      Other, {{177.0, 298.0}, {382.0, 68.0}}
      Other, {{0.0, -3.0}, {320.0, 146.0}}
      Other, {{0.0, 143.0}, {320.0, 30.0}}, identifier: 'UPCOMING EVENTS'
      Other, {{320.3, 73.0}, {415.7, 556.0}}
      Other, {{177.0, 297.0}, {382.0, 1.0}}
      Other, {{16.0, 27.0}, {288.0, 106.0}}
      Other, {{320.3, 73.0}, {415.7, 106.0}}
      Other, {{320.3, 219.0}, {415.7, 72.0}}
      Other, {{320.3, 331.0}, {415.7, 67.0}}
      Other, {{320.3, 438.0}, {415.7, 63.0}}
      Other, {{320.3, 541.0}, {415.7, 48.0}}
      Other, {{336.3, 73.0}, {383.7, 28.0}}
      Other, {{320.3, 331.0}, {415.7, 12.0}}
      Other, {{320.3, 348.0}, {415.7, 50.0}}
      Other, {{336.3, 463.0}, {399.7, 1.0}}
      Other, {{336.3, 469.0}, {399.7, 24.0}}
      Other, {{320.3, 348.0}, {415.7, 1.0}}
      Other, {{320.3, 397.0}, {415.7, 1.0}}
    }
    ↪︎Find: Elements matching predicate '"EventEditor-TextField-Desc" IN identifiers'
      Output: {
        Other, {{177.0, 162.0}, {382.0, 78.0}}, identifier: 'EventEditor-TextField-Desc', value: Description
      }

平台

  • 设备:iPhone 8Plus 模拟器
  • 操作系统:iOS 12.1
4

0 回答 0