2

I'm writing the UI tests for an application that contains huge cells(~ 1000) in its tableview. Trying to access the cell elements will show the below error:

Failed to get matching snapshots: Timed out while evaluating UI query.

Scenarios:

  • If I try to get the cells count by XCUIApplication().tables.firstMatch.cells.count, it throws the exception
  • Printing XCUIApplication().debugDescription for the first time prints the whole hierarchy (though, it takes ~10secs to print)
  • After that, If I try to print the exact same line XCUIApplication().debugDescription, throws an exception

I can not check the cells counts and can't able to access the cell elements. The system is trying to evaluate all UI elements whenever I access an element in the XCUIApplication().

This is the expected behaviour, so I thought of making a copy of XCUIApplication() data locally and deal with my queries with that locally saved instance. So, I tried this:

private lazy var dummyApp: XCUIApplication = {
   return XCUIApplication()
}()

Here, I used a lazy variable(because I want to call the XCUIApplication() only once to stop the system from taking the snapshots) that returns XCUIApplication() instance and tried to print the cell counts like:

dummyApp.tables.firstMatch.cells.count

This also throwing the same error.

Question:

Is there a way to save XCUIApplication()'s whole structure with a local variable? Or can I stop/extend the snapshot process before accessing an element?

P.S: I'm using Xcode 11.3.1. I'm facing this issue for a long time. Posting this problem as a separate question since XCUITest changed its interaction with the application from Xcode 9.

sandpat
  • 1,478
  • 12
  • 30
Confused
  • 3,846
  • 7
  • 45
  • 72

1 Answers1

1

Answer:

You can use

let snapshot = app.snapshot()

Which gives you a snapshot of the app and all the elements and subelements.
https://developer.apple.com/documentation/xctest/xcuielementsnapshot https://developer.apple.com/documentation/xctest/xcuielementattributes


Talking about performance.

Your UITableView is too big for black-box testing frameworks like XCTest (Appium, Katalon Studio etc).

If you want to test it, you should consider switching to EarlGrey 2.0 (or other grey-box frameworks). The good thing is you can use EarlGrey 2.0 alongside your existing XCTest tests.

You can read more about testing frameworks performance in this article https://devexperts.com/blog/ios-ui-testing-frameworks-performance-comparison/

P.S. Such big tables are also bad for users. Consider redesigning your UI.

Roman Zakharov
  • 2,185
  • 8
  • 19