Sample Project
This is a sample project that showing the issue. It's storyboard based, but method of building interface doesn't matter. It's UIViewController
with UIScrollView
for entire screen and 128 pts height view that is on top of this UIScrollView
.
Inside scroll view there is an UIView
that has 2000 pts
height and UIButton
in the center.
Link here: https://github.com/JakubMazur/UITestsDemo
Problem
- I'm trying to tap this green button with
XCUITest
usingapp.buttons["Tap Me!"].tap()
- XCUITest get identifiers from elements on screen for entire scroll view that works fine.
- According to this reply on a thread on Apple Developer Forum written by Apple Framework Engineer I shouldn't scroll manually to get to the button and yes, this is partially true.
- What is happening when code from (1) is executed is that button is scrolled just enough to be visible on screen but it's still not hittable, because other (purple view) is on top of
UIScrollView
What is working
If I run a test written like this:
func testThatDoWorkButItsSlow() {
app.scrollViews.firstMatch.swipeUp()
app.buttons[buttonLabel].tap()
}
that is scrolling up and then looks for a button this will work, but it's slow and so inaccurate that is hardly usable.
What I cannot do
Disabling userInteractions
on purple view. In real example I still need touches for this (purple) view.
Questions
- Is there a way to use precise scrolling in XCTest for this case?
- Or is there a way to set
contentOffset
scrollview to other value that will make this button more centered on a screen compared to action oftap()
? - Or there is a way to fast scroll to the bottom (without animations) and maybe moving only up for each element?