问题
So i am trying to access and confirm the presence of a password textfield in my uitests but as soon as assign their isSecureTextEntry = true the tests can no longer find them by the accessID. Does any one know why? and if there is a way around this so that i can find them and use them in the tests? Preferably so that i can still use the access ID to locate them in the tests.
My test is very simple:
func testHasPasswordTextField() {
let passwordTextField = app.textFields[AccesID.passwordTextField]
XCTAssertTrue(passwordTextField.isHittable)
}
I get the following error when running the test:
"No matches found for Find: Elements matching predicate '"Password" IN identifiers' from input {( TextField, 0x600000193e80, traits: 146029150208, identifier: 'Email', placeholderValue: 'Email' )}".
the test passes happily if isSecureTextEntry = false(or just not set)
回答1:
Ok, so a colleague just found out for me that when testing and finding a textfield by its accessabilityidentifier and isSecureTextEntry is set to true the textfield is now found in tests as secureTextFields so my test passes as before but now looks like this:
func testHasPasswordTextField() {
let passwordTextField = app.secureTextFields[AccesID.passwordTextField]
XCTAssertTrue(passwordTextField.isHittable)
}
来源:https://stackoverflow.com/questions/45551667/access-id-does-not-work-when-testing-a-textfield-with-issecuretextentry-true