As EarlGrey runs in the process and there is no install/uninstall process involved as in XCUI test framework, I expected tests to run faster but I noticed it is almost the same speed as XCUI test framework. Any reasons?
It's very slow to get TabBar or NavBar items. How can I speed up the process?
I'm using this for TabBar elements to match
let tabButtonMatcher: GREYMatcher = grey_allOf([grey_accessibilityLabel("Something"), grey_accessibilityTrait(UIAccessibilityTraitButton), grey_sufficientlyVisible()])
EarlGrey.selectElement(with: tabButtonMatcher).perform(grey_tap()).assert(grey_sufficientlyVisible())
Similar for NavBar buttons also
let navMatch: GREYMatcher = grey_allOf([grey_accessibilityID("Something"), grey_accessibilityTrait(UIAccessibilityTraitButton), grey_sufficientlyVisible()])
EarlGrey.selectElement(with: navMatch).perform(grey_tap())
You must remove
grey_sufficientlyVisiblefrom your matchers because it doesn't make sense. This matcher is guaranteed to work well in theassertstatement, but it seems it's inefficient to pass as a matcher parameter.EarlGrey interacts with touch events on the run loop and, generally, it interacts with the application as well as a real user. Its unlikely tests will be fast in this case, especially compared with KIF which calls selectors on UI elements instead of passing touch events. That's not bad, it's an expected behavior for functional tests. By the way, you could speed up tests by disabling animations:
Regarding your question related to matchers, I would suggest you try several approaches and find one which is suited in your case.
At first sight, it should be worth to just find a
UITabBarItemusinggrey_kindOfClass.Matcher example (not working)
But it's not the working solution. Let's see on view hierarchy:
So if you rely on
UITabBarItemit doesn't work, because there is no such element. You can see, that there is a private UIKit class calledUITabBarButtonwhich is not supposed to interact with. Moreover, it's not a subclass ofUIButton, but it's a subclass ofUIControlInstead, I would recommend to select element on
UITabBarusinginRootfunction.Matcher example (working)
In this case, you find an element, which has the expected text and which is located on the
UITabBar.For selection elements on the navigation bar it's possible to use variations of this matcher:
Matcher example to find the element on navigation bar