Timestamped Event Matching Error: Failed to Find Matching Element

XCUITest - Failed to find matching element

You can use the Debug View Hierarchy or the XCode open developer tool Accesibility Inspector from bottom to top looking for the view that isn't accessibility enabled.

XCUITest: Failed to find Matching Element

I don't know what is the exact problem with your assertion. But this steps may help you.

  • Put a breakpoint on this line XCTAssertTrue(app.otherElements["ChildViewController"].exists)
  • Now run the test case. When the control reaches this line, type this line in the debugger po XCUIApplication().buttons.debugDescription then tap the enter button
  • It will print all buttons in your current view. Now check whether the "closeButton" exists in that list
  • If it exists, check the identifier name. Make sure that it is "closeButton" (Identifier is case sensitive, also spaces in the identifiers matters)
  • If the identifier is right, try to find out the closeButton's exact view hierarchy. Means, instead of just checking like app.buttons["closeButton"].exists, try like app.navigationBars.otherElements["someName"].buttons["closeButton"].exists

(This seems funny, but giving the exact location path of the element is a good practice, and it will work sometimes)

Note: This error "Failed to find Matching Element" on UI recording will happen if the system can not locate the element with proper identifier while doing action on it. So my guess is, your closeButton does not have proper identifier or it is not added to the current window.

Cheers!!

iOS 14 / UI Testing DatePicker

The problem is only how to tap outside the expanded picker to dismiss it. You can do that with a simple click, which you can emulate using an extension:

extension XCUIApplication {
func tapCoordinate(at point: CGPoint) {
let normalized = coordinate(withNormalizedOffset: .zero)
let offset = CGVector(dx: point.x, dy: point.y)
let coordinate = normalized.withOffset(offset)
coordinate.tap()
}
}

Here's a somewhat naive approach, based on the recording; you can clean it up as desired:

func testExample() throws {
let app = XCUIApplication()
app.launch()
XCTAssertTrue(app.cells["Date, Date Picker, Sep 24, 2020"].exists)
app.tables.datePickers.containing(.other, identifier:"Date Picker").element.tap()
app.datePickers.collectionViews.buttons["Friday, September 4"].otherElements.containing(.staticText, identifier:"4").element.tap()
app.tapCoordinate(at: CGPoint(x:30,y:30))
XCTAssertTrue(app.cells["Date, Date Picker, Sep 4, 2020"].exists)
}

Of course, that works only today. But it will get you going.

If you want to see that the dismiss tap work, add a delay:

    app.tapCoordinate(at: CGPoint(x:30,y:30))
let delayExpectation = XCTestExpectation()
delayExpectation.isInverted = true
wait(for: [delayExpectation], timeout: 1)

You will see that the expanded picker does indeed dismiss before the test ends.



Related Topics



Leave a reply



Submit