【问题标题】:XCTest UI Testing - Drag and dropXCTest UI 测试 - 拖放
【发布时间】:2016-11-23 12:51:10
【问题描述】:

我正在尝试将图像拖动到我的应用程序中的特定布局,我可以点击图像但无法跨拖放区移动。并尝试了以下解决方案:

1

let startCoord = XCUIApplication().cells.element(boundBy: 0).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.01));
let endCoord = startCoord.withOffset(CGVector(dx: 0.0, dy: -900));
startCoord.press(forDuration: 0.25, thenDragTo: endCoord)

2

let fromCoordinate = XCUIApplication().coordinate(withNormalizedOffset:CGVector(dx: 5, dy:10))
let toCoordinate = XCUIApplication().coordinate(withNormalizedOffset:CGVector(dx: 5, dy: 20))
fromCoordinate.press(forDuration: 5, thenDragTo: toCoordinate)
Locating through coordinates.

但我仍然无法找出解决方案。

有人知道如何在 Xcode 8.1 中正确执行拖放操作吗?

【问题讨论】:

  • 你能打印出方法 1 和 2 的 from/to 坐标 x 和 y 值,然后发布吗?

标签: xcode xctest xcode-ui-testing


【解决方案1】:

先看功能说明:

 public func pressForDuration(duration: NSTimeInterval, thenDragToElement otherElement: XCUIElement)

很明显,您必须使用 XCUIElement 作为“thenDragTo”参数。

您将 XCUICoordinate 作为无效参数传递。

尽量取图像的 XCUIElement,而不是取 XCUIElement 要拖动的地方,然后使用函数。下面给出一个简单的例子:

let firstImage = app.images.elementBoundByIndex(0)
let secondImage = app.images.elementBoundByIndex(1)
firstImage.pressForDuration(forDuration: 5, thenDragTo: secondImage)
//this will drag the first image to the second image location.

希望这对您有所帮助,并让我知道发生了什么。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-12-10
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
  • 1970-01-01
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多