2

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?

gran_profaci
  • 8,087
  • 15
  • 66
  • 99
  • Are the images being downloaded? Is there any network activity or animation that runs when the data is being populated? And does the data source preload all data or does it do it on demand? – khandpur Aug 02 '16 at 04:10
  • I did have a network request being made before that was making the UI freeze since it tool longer than the interaction duration to complete. But that's been removed now. The data is all preloaded into an array and there isn't any animation happening. – gran_profaci Aug 03 '16 at 17:28

1 Answers1

1

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.

khandpur
  • 705
  • 3
  • 12