Xcode UI测试 - 拖放

问题描述 投票:2回答:4

我正在尝试创建XCTestCase以在我的大纲视图中测试重新排序(在OS X应用程序中)。当我使用UI测试记录功能时,Xcode打印出:

window.outlines.staticTexts["<cell which I want to move>"].click()

我尝试在大纲视图的内部或外部拖动单元格,Xcode生成相同的无用代码。

有谁知道如何在Xcode 7中正确测试拖放?

xcode swift cocoa xcode7-beta5 xcode-ui-testing
4个回答
7
投票

不确定这是否是新的,但是在Xcode 7.2中,如果你看一下XCUIElement的标题,那么OS X就有一个clickForDuration(thenDragToElement:)函数。似乎可以用NSOutlineView为我工作。

这是从标题...

/*!
 * Clicks and holds for a specified duration (generally long enough to start a drag operation) then drags
 * to the other element.
 */
public func clickForDuration(duration: NSTimeInterval, thenDragToElement otherElement: XCUIElement)

1
投票

同样的问题。没有解决方案。看起来可访问性不支持d-n-d,Apple文档说:Provide alternatives for drag-and-drop operations.


0
投票

我唯一可以建议的是尝试检查被测试代码的可访问性功能。 UI测试需要具有可访问性信息,以便能够了解UI中发生的情况。请参阅视频中大约39:30的Apple WWDC15 UI Testing video,了解如何解决UI录制无法正确生成代码的问题。


0
投票

使用Xcode 9.4.1 Swift:

func press(forDuration duration: TimeInterval, thenDragTo otherElement: XCUIElement)

例:

let ele: XCUIElement = XCUIApplication()!.otherElements.matching(identifier: "element_identifier").element(boundBy: 0)
ele.press(forDuration: <timeIntervalInSec>, thenDragTo: <destination_XCUIElement>)

参考:API Doc

© www.soinside.com 2019 - 2024. All rights reserved.