25

UITableViewXcode 7 (ベータ 3) の新しい Xcode UI テスト フレームワークを使用して、更新するプルを複製しようとしています。

私の現在のアプローチは、テーブルからテーブルの下にある要素にドラッグすることです。UIToolbarこれは、またはのようなテーブルの下に固定アイテムがある場合に機能しますが、UITabBarまたはUITabBarUIToolbarメソッドを使用せずに引っ張って更新/ドラッグ アクションを実行する方法がわかりませんXCUIElement

func pressForDuration(duration: NSTimeInterval, thenDragToElement otherElement: XCUIElement)

リフレッシュの成功

しかし、ツールバー/タブバーがなく、セルを使用してドラッグしようとすると失敗します

リフレッシュの失敗

これは私のコードの関連部分です:

func testRefresh() {
    //For testing cell
    for _ in 0...9 {
        addCell()
    }
    refreshTable()
}

func refreshTable(var tbl: XCUIElement? = nil) {
    let app = XCUIApplication()

    if tbl == nil {
        let tables = app.tables
        if tables.count > 0 {
            tbl = tables.elementAtIndex(0)
        }
    }

    guard let table = tbl else {
        XCTFail("Cannot find a table to refresh, you can provide on explicitly if you do have a table")
        return
    }

    var topElement = table
    let bottomElement: XCUIElement?

    //Try to drag to a tab bar then to a toolbar then to the last cell
    if app.tabBars.count > 0 {
        bottomElement = app.tabBars.elementAtIndex(0)
    }
    else if app.toolbars.count > 0 {
        bottomElement = app.toolbars.elementAtIndex(0)
    }
    else {
        let cells = app.cells
        if cells.count > 0 {
            topElement = cells.elementAtIndex(0)
            bottomElement = cells.elementAtIndex(cells.count - 1)
        }
        else {
            bottomElement = nil
        }
    }
    if let dragTo = bottomElement {
        topElement.pressForDuration(0.1, thenDragToElement: dragTo)
    }
}

func addCell() {
    let app = XCUIApplication()
    app.navigationBars["Master"].buttons["Add"].tap()
}

その他の失敗した試行:

  • swipeDown()(それも複数回)
  • scrollByDeltaX/deltaY(OS X のみ)
4

3 に答える 3

22

API を使用してXCUICoordinate、必ずしも特定の要素に関連付けられていなくても、画面上の特定のポイントを操作できます。

  1. テーブルの最初のセルへの参照を取得します。次に、オフセットがゼロの座標を作成しますCGVectorMake(0, 0)。これにより、最初のセルの真上でポイントが正規化されます。
  2. 画面のさらに下に架空の座標を作成します。dy(引っ張って更新するジェスチャーをトリガーするのに必要な最小量は 6 であることがわかりました。)
  3. 最初の座標をつかみ、2 番目の座標にドラッグして、ジェスチャを実行します。

ここに画像の説明を入力

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

動作するサンプル アプリと共に詳細情報も利用できます。

于 2015-09-21T12:08:59.170 に答える
5

ジョーが提案したような座標を使用して、そのようなタスクを実行できました。しかし、私はさらに一歩進んだcoordinateWithOffset()

let startPosition = CGPointMake(200, 300)
let endPosition = CGPointMake(200, 0)
let start = elementToSwipeOn.coordinateWithNormalizedOffset(CGVectorMake(0, 0)).coordinateWithOffset(CGVector(dx: startPosition.x, dy: startPosition.y))
let finish = elementToSwipeOn.coordinateWithNormalizedOffset(CGVector(dx: 0, dy: 0)).coordinateWithOffset(CGVector(dx: endPosition.x, dy: endPosition.y))
start.pressForDuration(0, thenDragToCoordinate: finish)

特定のポイントから別の特定のポイントにドラッグできるようになりました。一部のビューにカスタム リフレッシュを実装しました。これを実装しているときに、これを使用してコントロール センターやトップ メニューにアクセスできることも発見しました。

于 2015-12-07T11:43:04.117 に答える