Ios 如何编写XUITestCase来驱动MDCMultilineTextField

Ios 如何编写XUITestCase来驱动MDCMultilineTextField,ios,xcode-ui-testing,mdc-components,Ios,Xcode Ui Testing,Mdc Components,在UI测试(XUITestCase)中,当我尝试让测试点击一个MDCMultilineTextField时,测试失败 元素和任何子体都没有键盘焦点 如果我尝试使用UI测试记录器并点击MDCMultilineTextField,则无法找到多行文本字段,错误如下: 时间戳事件匹配错误:找不到匹配元素 我的测试用例 let descField = app.otherElements["EventEditor-TextField-Desc"] let exp = expectation(for: NSP

在UI测试(XUITestCase)中,当我尝试让测试点击一个
MDCMultilineTextField
时,测试失败

元素和任何子体都没有键盘焦点

如果我尝试使用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
的可访问性标识符

运行测试时,它无法告诉
元素或任何子代都没有键盘焦点。
并将
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
      }
平台

  • 设备:iPhone8Plus模拟器
  • 操作系统:iOS 12.1