如果我取消注释注释代码,我的测试不会成功,否则它会成功(XCTAssertEqual) 我可以知道如何检查屏幕上是否存在登录按钮,以及为什么 XCTAssertEqual 不起作用
func testExample() {
let usernameTextField = app.textFields["Username"]
usernameTextField.tap()
usernameTextField.typeText("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e7868584a7808a868e8bc984888a" rel="noreferrer noopener nofollow">[email protected]</a>")
let passwordTextField = app.textFields["Password"]
passwordTextField.tap()
passwordTextField.typeText("abc123")
app.buttons["Login" ].tap()
//let loginButton = app.staticTexts["Login"]
//XCTAssertEqual(loginButton.exists, true)
app.navigationBars["UIView"].buttons["Back"].tap()
}
最佳答案
查找登录按钮时,使用buttons
而不是staticTexts
。文本标签是按钮组件的一部分。
let loginButton = app.buttons["Login"]
XCTAssertEqual(loginButton.exists, true)
关于ios - XCTAssertEqual 测试在 ios 的 UI 测试中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45651460/