Search code examples
xcodeswiftcocoaxcode7-beta5xcode-ui-testing

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?


Solution

  • 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)