Search for XCUIElement is too slow

87 views Asked by At

I am using XCUITest for UI-based testing of an iOS app.

A major (almost showstopping) problem in the project is performance when searching for elements in the visual tree.

Exemplification:

Front-screen of app consists of a stack of horizontal sliders containing about 20 views each. Each of these (slider) child views are itself a complex view with a deep hierarchy.

At the top of all this there is a button or two which must be tapped as part of the test.

When app is loading and sliders are not populated yes, it takes about 2-4 seconds to search and get an XCUIElement to a button in the screen's top. When app is finish loading and all sliders are populated, it takes a minut. BIG PROBLEM.

Therefore, I am convinced that it is the amount of elements in the visual tree that slows down the process.

I have tried a lot of different approaches to speed up the search, but all in vain.

What have been tried:

  1. Normal approach like: app.buttons["name of button"].tap()
  2. Same as 1, but get XUIElement before app loads
  3. Use XCUIXoordinates
1

There are 1 answers

0
Roman Zakharov On

You can speed up things by using firstMatch. It will stop searching the UI tree asap.

app.buttons["name of button"].firstMatch().tap()

This code will tap the first button or fail (because there is no matching button(s)), while the code you send will tap the only button or fail (because there are no buttons or more than one)