ios - Xcode UI 测试按钮未点击

标签 ios xcode swift user-interface

您好,我是 UI 测试新手,而且很 swift 。

我想做的只是点击 "+"右上角的按钮,然后点击 "first option"那出现了。 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

关于ios - Xcode UI 测试按钮未点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37685425/

相关文章:

iphone - Xcode - 如何更改应用程序/项目名称 : what do I need to to update and check?

iOS UITextView : URL Detection for links with country domain and without "http" prefix

swift - 自从我在 swift/xcode 中关闭应用程序以来,已经过去了几秒?

ios - Xcode 7 动画中的 UITesting 重复动画使测试失败

ios - UINavigationViewController 中的大量 SceneKit 场景需要很长时间才能解除分配

ios - 退出应用程序后未安装应用程序

ios - 为什么我无法在嵌套调用尝试中创建 url

ios - Xcode 5 的新文档解析是如何工作的?

iOS/Swift - 第一次使用后无法让键盘外观移动 View

ios - 解析 - 从关系中获取对象