-1

Is it possible to catch the following exception?

"Failed to get matching snapshots"

Most of the stability issues with XCUITest is due to not having a proper method to wait for element to exist. Tried exists(), waitforexistence(),xctwaiter waits etc. In all cases it fails randomly with above error. Is there a way we have handle this exception do a retry in our tests itself.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Please add some sample code and output generating the failure. You may also wish to review this SO question: https://stackoverflow.com/questions/44429118/ui-testing-fails-with-error-failed-to-get-snapshot-within-15-0s – ablarg Feb 11 '20 at 20:48

1 Answers1

0

You should stick to combination of two methods Use it for every flaky element

button.waitForExistence()
button.tap()
Roman Zakharov
  • 2,185
  • 8
  • 19
  • The problem, is waitForExistence() itself throws error.. So is there a way to catch that exception ? – Satheesh Kumar Feb 13 '20 at 16:45
  • https://developer.apple.com/documentation/xctest/xcuielement/2879412-waitforexistence No it does not. It only returns Boolean value indicating waiting was successful. – Roman Zakharov Feb 14 '20 at 11:06
  • yes, I am aware of the documentation part, but this is the case when you actually run the test. You get an exception and the test fails. Example Error log: Checking existence of `"ios close icon" Button` t = 117.83s Assertion Failure: Extensions.swift:171: Failed to get matching snapshots: Error getting main window kAXErrorServerNotFound t = 117.85s Capturing element debug description – Satheesh Kumar Feb 15 '20 at 07:52
  • Well, it is not a thrown error, it is a fail. It is hard to tell what caused it since a very little description of your problem. As mentioned by ablarg earlier, the question is not very informative. – Roman Zakharov Feb 17 '20 at 11:56