2015-12-08 53 views
3

例如, 我有一个素描平板应用程序,我想通过绘制来测试它。我想指定一个(x,y)坐标,并使其点击并拖动到另一个(x,y)坐标。如何在Xcode UI测试脚本中执行轻击和拖动操作?

这可能在Xcode UI测试?

乔提供了一个解决这个问题: 用客观的C,我的代码看起来是这样的:

XCUICoordinate *start = [element2 coordinateWithNormalizedOffset:CGVectorMake(0, 0)]; 
XCUICoordinate *finish = [element2 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)]; 
[start pressForDuration:0 thenDragToCoordinate:finish]; 

其中element2是XCUIElement我不得不执行的阻力。

回答

18

您可以使用XCUICoordinate在UI测试中点击并拖动元素。以下是通过表格单元坐标的how to pull to refresh的示例。

let firstCell = app.staticTexts["Adrienne"] 
let start = firstCell.coordinateWithNormalizedOffset(CGVectorMake(0, 0)) 
let finish = firstCell.coordinateWithNormalizedOffset(CGVectorMake(0, 6)) 
start.pressForDuration(0, thenDragToCoordinate: finish) 

如果你没有的元素引用您应该能够创建基于关闭的XCUIApplication任意坐标。

let app = XCUIApplication() 
let fromCoordinate = app.coordinateWithNormalizedOffset(CGVector(dx: 0, dy: 10)) 
let toCoordinate = app.coordinateWithNormalizedOffset(CGVector(dx: 0, dy: 20)) 
fromCoordinate.pressForDuration(0, thenDragToCoordinate: toCoordinate) 

UI测试没有正式文件,但我刮头放在一起的XCTest Reference,如果你有兴趣了解更多的细节。

+0

谢谢乔!像魅力一样工作!唯一的问题是我试图找到执行操作的元素。 –

+0

作品也刷卡确认。干得好@JamesGoe –

相关问题