I've been able to get UI Tests working on Apple Watch with Xcode 12.5 / Watch OS 7.0 on the simulator (with the help of some Apple engineers during a WWDC session). I can automatically press buttons and check for text on the screen, which is great.
What I cannot do however, is scroll the screen up or down, which severely limits the ability to reach some buttons and thus the testing.
I'm using XCUIApplication().swipeUp()
to try to scroll. What's also not working is the record/playback of UI tests on Apple Watch.
Has anyone been able to achieve a scroll up/down in UI tests on Apple Watch, and if so, how?
After a lot of digging around, I've been able to find the following solution/workaround:
func scrollUp() {
let app = XCUIApplication()
let relativeTouchPoint = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 1.0))
let relativeOffset = app.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: -1))
relativeTouchPoint.press(forDuration: 0, thenDragTo: relativeOffset)
}