Xcode UI测试 - 拖放

时间:2015-08-19 11:36:43

标签: xcode swift cocoa xcode7-beta5 xcode-ui-testing

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

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

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

有谁知道如何测试阻力和放大器在Xcode 7中正确删除?

4 个答案:

答案 0 :(得分:7)

不确定这是否是新的,但在Xcode 7.2中,如果你查看XCUIElement的标题,那么OS X的sa clickForDuration(thenDragToElement:)函数。似乎对我有用{ {1}}。

这是来自标题......

NSOutlineView

答案 1 :(得分:1)

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

使用Xcode 9.4.1 斯威夫特:

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

相关问题