在Swift中使用UITextfield类可以执行如下函数:
private func signIn() {
if emailTextField.text?.characters.count == 0 {
invalidEmailLabel.text = NSLocalizedString("Required", comment: "Required text field")
Constants.FormValidation.showValidationLabel(invalidEmailLabel)
return
}
有没有办法用XCUIElements做同样的事情或类似的事情?
我想做这样的事情:
func testExample() {
let app = XCUIApplication()
let emailTextField = app.textFields["username"]
if emailTextField.text.characters.count == "0"{
let emailTextField = app.textFields["username"]
emailTextField.tap()
emailTextField.typeText("example")
let passwordTextField = app.secureTextFields["password"]
passwordTextField.tap()
passwordTextField.typeText("whatever")
app.buttons["Done"].tap()
}
if emailTextField.text.characters.count != "0"{
let passwordTextField = app.secureTextFields["password"]
passwordTextField.tap()
passwordTextField.typeText("whatever")
app.buttons["Done"].tap()
}
如何才能使其有效?
感谢。
答案 0 :(得分:1)
您可以通过执行以下操作来计算文本字段元素的字符:
let emailValue = emailTextField.value as! String
if emailValue.characters.count == 0 {
// do something
}