使用isSecureTextEntry = true测试文本字段时,访问ID不起作用 [英] Access ID does not work when testing a textfield with `isSecureTextEntry = true`
问题描述
所以我试图访问并确认我的uitest中是否存在密码文本字段,但是一旦分配了它们的isSecureTextEntry = true
,测试就不再可以通过accessID找到它们.有谁知道为什么吗?并且是否有办法解决这个问题,以便我可以找到它们并在测试中使用它们?最好让我仍然可以使用访问ID在测试中找到它们.
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.
我的测试非常简单:
func testHasPasswordTextField() {
let passwordTextField = app.textFields[AccesID.passwordTextField]
XCTAssertTrue(passwordTextField.isHittable)
}
运行测试时出现以下错误:
I get the following error when running the test:
找不到匹配项:输入{( TextField,0x600000193e80,特征:146029150208,标识符:'Email',占位符值:'Email' )} ".
"No matches found for Find: Elements matching predicate '"Password" IN identifiers' from input {( TextField, 0x600000193e80, traits: 146029150208, identifier: 'Email', placeholderValue: 'Email' )}".
如果isSecureTextEntry = false
(或未设置),则测试顺利通过
the test passes happily if isSecureTextEntry = false
(or just not set)
推荐答案
好,所以一位同事为我发现,在通过accessabilityidentifier
和isSecureTextEntry
测试并查找文本字段时,将其设置为true时,现在在测试中以secureTextFields
找到,因此我的测试像以前一样通过了,但现在看起来像这样:
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)
}
这篇关于使用isSecureTextEntry = true测试文本字段时,访问ID不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!