Scroll in UI Tests on Apple Watch not working

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?

Answered by Ronvtw in 679780022

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)
}

I'm facing the same issue for UI tests for our watch apps. Unable to swipe up or swipe down using the methods swipeUp(), swipeDown(). I've also not found any methods that support scroll using crown which would be necessary for UI testing. Recording option is not working on Xcode 12.5 and Xcode 13 beta.

Hope there is a solution/workaround soon.

Accepted Answer

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)
}
Scroll in UI Tests on Apple Watch not working
 
 
Q