How to simulate scrolling a table or collection using Subliminal?

I'm currently trying to use KIF and Subliminal to test iOS integration. But I still can't figure out how to simulate scrolling in a table or collection view using both structures. Like scrolling to the bottom of a table or collection view.

EDIT 1 :

I made a simple application to view one collection here https://github.com/nicnocquee/TestSubliminal

Basically I want to test the last cell label. I can not do

SLElement *lastLabel = [SLElement elementWithAccessibilityLabel:@"Label of the last cell"]; [lastLabel scrollToVisible]; 

because the label does not exist yet until the collection view scrolls from the bottom.

EDIT 2 :

I answered Aaron with the answer. But Jeffrey also works :)

+4
source share
3 answers

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"); // Cause the collection view to scroll to the bottom. SLAskApp(scrollToBottom); SLElement *lastLabel = [SLElement elementWithAccessibilityLabel:@"This is cell 19"]; SLAssertTrue([UIAElement(lastLabel) isVisible], @"Last cell should be visible at this point"); } 
0
source

You can also simulate user scrolling through a collection looking for a cell by dragging and dropping the collection view until the cell becomes visible:

 while (!SLWaitUntilTrue([UIAElement(lastLabel) isValidAndVisible], 1.0)) { [[SLWindow mainWindow] dragWithStartOffset:CGPointMake(0.5, 0.75) endOffset:CGPointMake(0.5, 0.25)]; } 

These offsets translate to drag up the middle of the collection view, from 75% down to 25% down. -isValidAndVisible allows -isValidAndVisible to check the visibility of a cell without worrying about whether it still exists (whereas -isVisible throws an exception if the cell does not exist). And I end -isValidAndVisible in SLWaitUntilTrue so that we allow collection viewing to complete scrolling before re-dragging.

Unlike the appAponGolden app solution for the app, this approach requires that you can identify a specific cell to scroll through. So I would use this approach as “scroll to cell”, while the application hook allows you to “scroll to position”.

+1
source

This is probably more invasive, but too simple - Go to SLUIAElement.m and add the following methods:

 - (void)scrollDown { [self waitUntilTappable:NO thenSendMessage:@"scrollDown()"]; } - (void)scrollUp { [self waitUntilTappable:NO thenSendMessage:@"scrollUp()"]; } 

You will also have to declare this method signature in the SLUIAElement.h file so that these new methods are visible in the test suite.

Then what you can do is add an accessibility identifier to the collection view, call that identifier and scroll it. Example:

 SLElement *scrollView = [SLElement elementWithAccessibilityIdentifier:@"scrollView"]; [scrollView scrollDown]; 
+1
source

Source: https://habr.com/ru/post/1497246/


All Articles