XCode UI 测试长按并左右拖动按钮

Shi*_*yal 5 unit-testing ios swift

我有一个按钮,就像 whatsapp 麦克风按钮一样,您可以长按并向左和向右移动它。

现在我需要为这个按钮编写一个测试用例。到目前为止,我所做的是,我可以拖动到特定位置。现在我需要左右拖动,但我找不到任何方法来做到这一点。

let app = XCUIApplication()
app.buttons["Launch Chat"].tap()

app.tables.staticTexts["shivam"].tap()

let chatbarElement = app.otherElements["chatBar"]

let button = chatbarElement.children(matching: .button).element(boundBy: 0)

let startPoint = button.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)) // center of element
var finishPoint = chatbarElement.coordinate(withNormalizedOffset: CGVector(dx: 0.7, dy: 0))

startPoint.press(forDuration: 3, thenDragTo: finishPoint)
Run Code Online (Sandbox Code Playgroud)

如您所见,此方法仅拖动到特定位置。但是我需要的是在特定的持续时间内向左和向右连续拖动它,我找不到任何方法来实现这一点。

PS:这不是swipeLeft和swipeRight,拖动是指长按后可以左右拖动按钮,而不是普通的点击。