簡體   English   中英

Xcode UI測試按鈕沒有點擊

[英]Xcode UI test button not tapping

嗨,我是UI測試和swift的新手。

我要做的只是點擊右上角的“+”按鈕,然后點擊顯示的“第一個選項” Xcode說我的測試成功,但我的水龍頭都沒有做任何事情。 這是我的代碼

func test1() {
    let app = XCUIApplication()
    let addButtonButton = app.navigationBars["Timesheets"].buttons["add button"]
    waitForElementToHittable(addButtonButton)
    addButtonButton.tap()

    let tablesQuery = app.tables
    tablesQuery.cells.elementBoundByIndex(0).forceTap()
}

這是waitForElementToHittable()和forceTap()的定義

 func waitForElementToHittable(element: XCUIElement,
                            file: String = #file, line: UInt = #line) {
    let existsPredicate = NSPredicate(format: "hittable == true")
    expectationForPredicate(existsPredicate,
                            evaluatedWithObject: element, handler: nil)

    waitForExpectationsWithTimeout(30) { (error) -> Void in
        if (error != nil) {
            let message = "Failed to hit \(element) after 30 seconds."
            self.recordFailureWithDescription(message,
                                              inFile: file, atLine: line, expected: true)
        }
    }
}

extension XCUIElement {
    func forceTap() {
        if self.hittable {
            self.tap()
        } else {
            let coordinate: XCUICoordinate =     self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
            coordinate.tap()
        }
    }
}

任何指導都將非常感謝。 謝謝。

你確實忘了啟動應用程序:

let app = XCUIApplication()
app.launch() // missing in your code

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM