UITest XCUIElementQuery缺少元素

时间:2018-02-19 07:31:32

标签: ios swift xcode uitextfield uitest

//Helper
class UITest: XCTestCase {
    final func setInitalCredentials() {
        print("\(app.textFields.count)") <-- prints (1)
        let loginTextField = app.textFields["LoginTextField"] <-- is found
        loginTextField.tap()
        let deleteKey = app.keys["delete"]
        let _ = deleteKey.waitForExistence(timeout: 2)
        deleteKey.press(forDuration: 2)
        loginTextField.typeText("login")

        let passwordTextField = app.textFields["PasswordTextField"] <- is not
        passwordTextField.tap()
        let _ = deleteKey.waitForExistence(timeout: 2)
        deleteKey.press(forDuration: 2)
        passwordTextField.typeText("password")
    }

    var app: XCUIApplication!

    override func setUp() {
        super.setUp()
        continueAfterFailure = false
        app = XCUIApplication()
        app.launch()
        app.launchArguments.append("--uitesting")
    }

    override func tearDown() {
        app.terminate()
        super.tearDown()
        app.launch()
    }
}

//Actual test
class UILoginViewTest: UITest {

    func testLogin() {
        setInitalCredentials()
        let loginButton = app.buttons["Connect"]
        loginButton.tap()
        let applicationRootView = app.otherElements["QuotesViewController"]
        let _ = applicationRootView.waitForExistence(timeout: 10)
        XCTAssert(applicationRootView.exists)
    }
}

我错过了什么?为什么找不到第二个UITextField?我确定所有ID都已设置,我甚至无法通过占位符或文字访问它,因为XCUIElementQuery告诉我只有1 UITextField

1 个答案:

答案 0 :(得分:0)

appsecureTextFields,其中包含任何`UITextFields&#39;安全文本输入。