提问人:chr0x 提问时间:10/22/2023 最后编辑:Jon Reidchr0x 更新时间:10/23/2023 访问量:38
如何在 XCTest 中使用 XCUICoordinate 执行多个拖动手势而不释放中间的元素?
How to perform multiple drag gestures using XCUICoordinate in XCTest without releasing the element in-between?
问:
在我的应用中,有一个卡片视图,当它被拖动到屏幕的一角(左、右、上、下)时,屏幕会显示卡片拖动到的角落。我已经编写了一个 UI 测试来验证此行为,但它目前需要我创建四个单独的卡片来运行测试。这是因为该卡在以下调用后被释放:
cardCenterCoordinate.press(forDuration: 0.1, thenDragTo: cardCenterCoordinate.withOffset(offset))
有没有办法在整个过程中保持拖动手势处于活动状态,并将同一张卡片移动到四个不同的方向,然后将其放回中心而不松开?
func testDragInteractionOnPracticeScreenFlashcards() throws {
let cardView = app.staticTexts["Card"]
XCTAssertTrue(cardView.waitForExistence(timeout: 5))
let hittableTimeout = 3.0
let cardCenterCoordinate = cardView.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
let screenSize = app.windows.element(boundBy: 0).frame.size
let distanceToMoveInX = screenSize.height * 0.5
let distanceToMoveInY = screenSize.width * 0.5
let checkpoints: [(String, CGVector)] = [
("Right", CGVector(dx: distanceToMoveInX, dy: 0)),
("Top", CGVector(dx: 0, dy: -distanceToMoveInY)),
("Left", CGVector(dx: -distanceToMoveInX, dy: 0)),
("Down", CGVector(dx: 0, dy: distanceToMoveInY))
]
for (label, offset) in checkpoints {
cardCenterCoordinate.press(forDuration: 0.1, thenDragTo: cardCenterCoordinate.withOffset(offset))
XCTAssertTrue(app.staticTexts[label].waitForExistence(timeout: hittableTimeout))
}
}
答: 暂无答案
评论