尝试创建一个 UITest,用于在文本字段中输入电子邮件地址/密码,然后点击登录按钮。使用 Xcode。
我看到 UITest 导航到正确的页面,但它没有检测到文本字段。我确保两个文本字段都选中了“辅助功能”框,并为它们提供了标识符。
我收到这个错误:
UI Testing Failure - No matches found for text field
func testExample() {
let app = XCUIApplication()
//Test login page
app.buttons["loginButton"].tap()
//Here it navigates to the desired page
let emailField = app.textFields["email"]
emailField.tap()
emailField.typeText("xxx.xx.edu")
let passwordField = app.textFields["password"]
passwordField.tap()
passwordField.typeText("xxx")
app.buttons["loginButton"].tap()
// let loginAlert = app.alerts["alertVC"]
// XCTAssertEqual(loginAlert.title, "Error")
}
可访问性指示符分别是“电子邮件”和“密码”。当我自己运行模拟器时,登录工作正常。
编辑:显然根本没有文本字段(计数 = 0),即使我看到它们并在页面上使用它们......
带有文本字段的 Storyboard图像:
最佳答案
如果 UITextFiled
设置了 SecureTextEntry
true
,您应该使用:
let passwordField = app.secureTextFields["password"]
关于Swift UITest - 找不到具有可访问性标识符的文本字段的匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43575480/