UI测试的ios-应用程序,开发了Xcode 8和迅捷3.2。
在将Xcode版本8升级到9之后,我面临一个处理拖放的问题
我想拖动一个元素[i.e. button],并将它放到另一个元素[i.e. on homepage]中。
对于Xcode 8,我使用以下方法实现了它:
let sourceElement = app.buttons["Video_Button"]
let destElement = app.scrollViews.scrollViews.images.element(boundBy: 0)
sourceElement.press(forDuration: 0.5, thenDragTo: destElement)但是上面的代码在Xcode 9和Swift 3.2中不起作用。
发布于 2017-12-15 13:48:40
实际上问题出现在iOS 11.0中。
在iOS 11.0中,一些层次结构元素未能、点击、或按下或longpress。
您必须使用元素中心点来执行、tap、或按或longpress。
**问题的解决方案的代码片段粘贴在下面。
首先,创建一个扩展方法,用于按下元素的中心,并将该元素拖到目标元素中心。
扩展方法低于
extension XCUIElement {
func dragAndDropUsingCenterPos(forDuration duration: TimeInterval,
thenDragTo destElement: XCUIElement) {
let sourceCoordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx:0.5, dy:0.5))
let destCorodinate: XCUICoordinate = destElement.coordinate(withNormalizedOffset: CGVector(dx:0.5, dy:0.5))
sourceCoordinate.press(forDuration: duration, thenDragTo: destCorodinate)
}
}然后,调用扩展方法,如下面所示
sourceElement.dragAndDropUsingCenterPos(forDuration: 0.5, thenDragTo: destElement)希望它能解决你的问题。让我知道你的反馈。
https://stackoverflow.com/questions/47813639
复制相似问题