Using SBTUITestTunnel for Scrolling in XCUITests
When creating XCUITests, you will use the following command to view the element hierarchy tree: po XCUIApplication()
However, sometimes elements won’t appear in the hierarchy tree until you scroll on the screen. XCode is supposed to scroll to an element automatically even when not in view, but we have not had success with this and it appears this is an open issue still.
So what to do?
SBTUITestTunnel allows you to define custom blocks of codes executed in the application target.
Set up your app to use SBTUITestTunnel and then you should be to have something similar to the following in your tests:
static var sbtApp: SBTUITunneledApplication?
Within the app code, you can create a file that has the following:
And have another extension where your view will extend the protocol shown above. This will allow you to have access to the table when the view appears/disappears. You can override the appropriate methods for your views. You want to ensure this code is only applied/ran when you are running the appropriate scheme for UI Tests so ensure you wrap this with a block ie.
Within your UI Test folder, you can then have a file that includes the following functions that will allow you to scroll to a point, element, or table row.
In your test file, you can then call these by doing something similar to the following:
SBTUITunnel also added some functionality for scrolling and these functions are shown here: https://github.com/Subito-it/SBTUITestTunnel/blob/master/Documentation/Usage.md#fine-grain-scrolling
I personally haven’t tried these out yet, but plan to in the near future.
Apple introduced a new UI Testing feature starting from Xcode 7 that is, quoting Will Turner on stage at the WWDC, a…