I was working on a basic iOS tutorial app and thought I could also start learning some EarlGrey
with it. The test that I'm automating has this flow -
I have a large UITableView and I pre-populate it with some random words that I generate. These can be quite long and I might have over 100 cells in my TableView.
In my test, I randomly select one of the words generated and search for it within the cell. Each cell has the following UI:
| |
| |Word| |Word-Count| | UIImage | |
| |
So in EarlGrey
-
- (void)setup {
[super setup];
GeneratorClass dataSource =
[[GeneratorClass alloc] initWithRandomData];
self.tableView.dataSource = dataSource;
_randomSelectedValue = dataSource.randomValue;
}
- (void)testTableElementVisible {
id<GREYMatcher> *cellMatcher = grey_allOf(grey_minimumVisiblePercent(0.0f),
grey_interactable(),
grey_isKindOfClass([UITableViewCell class]),
grey_text(_randomSelectedValue), nil);
[[EarlGrey selectElementWithMatcher:cellMatcher]
asserWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:cellMatcher]
performAction:grey_tap()];
}
However, on Jenkins, this test takes quite long to run and fails with "Timeout (currently set to 30) occurred when looking for elements."
The screen is frozen and though locally I can see the tap occur, I haven't been able to have it pass on it. Is there any way by which I can speed this test up or is there something wrong that I'm doing here that's causing EarlGrey to freeze?
No wonder it's taking so long. You have grey_minimumVisiblePercent
as the first matcher in grey_allOf
. What that does is runs every element in the ui hierarchy through those matchers in the order in which they are specified and stops only when one of the matcher fails or all of them pass (i.e. match). You should always do most selective to least selective matchers in order to avoid this problem. Using that logic, grey_text(_randomSelectedValue)
seems to be the most selective so use that as the first matcher, then use the others in the order of decreasing selectiveness.