How to write XCUITestCase to drive an MDCMultilineTextField

208 views Asked by At

In a UI Test (XCUITestCase), when I try to let the test tap an MDCMultilineTextField, the test fails with

Neither element nor any descendant has keyboard focus.

If I try to use the UI test recorder and tap the MDCMultilineTextField it fails to find the multiline text field with the error:

Timestamped Event Matching Error: Failed to find matching element

My test-case

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()

, where EventEditor-TextField-Desc is the accessibility identifier assigned to the MDCMultilineTextField.

When running the test, it fails telling Neither element nor any descendant has keyboard focus. and marks the descField.typeText("Desc 4") line as having the error. Detailed error description:

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
      }

Platform

  • Device: iPhone 8Plus simulator
  • OS: iOS 12.1
0

There are 0 answers