Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode UI Testing - Drag and Drop

I'm trying to create XCTestCase to test reordering in my outline view (in OS X app). When I use UI Test Recording feature, Xcode prints this:

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

I tried dragging the cell both inside or outside outline view, Xcode generates the same useless code.

Does anyone know how to test drag & drop correctly in Xcode 7?

like image 308
egor.zhdan Avatar asked Sep 16 '25 19:09

egor.zhdan


2 Answers

Not sure if this is new, but in Xcode 7.2, if you look at the header for XCUIElement, there's a clickForDuration(thenDragToElement:) function for OS X. Seems to work for me with NSOutlineView.

This is from the header...

/*!
 * 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)
like image 152
harrisg Avatar answered Sep 19 '25 17:09

harrisg


With Xcode 9.4.1 Swift:

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

Example:

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

Refer: API Doc

like image 45
Sravan Avatar answered Sep 19 '25 18:09

Sravan