Using SBTUITestTunnel for Scrolling in XCUITests

Ronell Lukasik
2 min readNov 25, 2020


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:

import FBSnapshotTestCase

static var sbtApp: SBTUITunneledApplication?



SBTUITunneledApplicationLaunchOptionDisableUITextFieldAutocomplete]) {}

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.

#if build_configuration_name


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:



Ronell Lukasik

Test Engineer Expert, Dog Mom