OGeek|极客世界-中国程序员成长平台

标题: ios - XCTAssertEqual 测试在 ios 的 UI 测试中不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:37
标题: ios - XCTAssertEqual 测试在 ios 的 UI 测试中不起作用

我有下面的 UI,我为此编写了 UI 测试用例- enter image description here

如果我没有注释注释代码,我的测试不会成功,否则它会成功 (XCTAssertEqual) 我可以知道如何检查屏幕上是否存在登录按钮,以及为什么 XCTAssertEqual 不起作用

func testExample() {

        let usernameTextField = app.textFields["Username"]
        usernameTextField.tap()
        usernameTextField.typeText("[email protected]")

        let passwordTextField = app.textFields["assword"]
        passwordTextField.tap()
        passwordTextField.typeText("abc123")

        app.buttons["Login" ].tap()

                //let loginButton = app.staticTexts["Login"]
                //XCTAssertEqual(loginButton.exists, true)

        app.navigationBars["UIView"].buttons["Back"].tap()


    }



Best Answer-推荐答案


在查找登录按钮时,使用 buttons 而不是 staticTexts。文本标签是按钮组件的一部分。

let loginButton = app.buttons["Login"]
XCTAssertEqual(loginButton.exists, true)

关于ios - XCTAssertEqual 测试在 ios 的 UI 测试中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45651460/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4