The problem is that the cell you are trying to find in the test case with the label "This is cell 19" does not exist until the collection has been scrolled. Therefore, we need to scroll the view first, and then look for the cell. The easiest way to scroll through the collection view using Subliminal is with the application. In (for example) your viewDidLoad view viewDidLoad you can register a view controller to respond to a specific message from any Subliminal test case, for example:
[[SLTestController sharedTestController] registerTarget:self forAction:@selector(scrollToBottom)];
and the view controller can implement this method as:
- (void)scrollToBottom { [self.collectionView setContentOffset:CGPointMake(0.0, 1774.0)]; }
This 1774 is just an offset that occurs to scroll the collection view in the test application to the end. In a real application, the application hook is likely to be more complex. (And in a real application, you would like to make sure that you call [[SLTestController sharedTestController] deregisterTarget:self] in your dealloc controller dealloc .)
To run the scrollToBottom method from a Subliminal test case, you can use:
[[SLTestController sharedTestController] sendAction:@selector(scrollToBottom)];
or a convenient macro:
SLAskApp(scrollToBottom);
The general SLTestController will send a SLTestController message scrollToBottom object registered to receive it (your view controller).
When the sendAction or SLAskApp returns your cell 19, it will already be visible, so you no longer have to worry about calling [lastLabel scrollToVisible] . Your complete test case might look like this:
- (void)testScrollingCase { SLElement *label1 = [SLElement elementWithAccessibilityLabel:@"This is cell 0"]; SLAssertTrue([UIAElement(label1) isVisible], @"Cell 0 should be visible at this point"); SLElement *label5 = [SLElement elementWithAccessibilityLabel:@"This is cell 5"]; SLAssertFalse([UIAElement(label5) isValid], @"Cell 5 should not be visible at this point");