UITest XCUIElementQuery 缺少元素

Posted

技术标签:

【中文标题】UITest XCUIElementQuery 缺少元素【英文标题】:UITest XCUIElementQuery missing elements 【发布时间】:2018-02-19 07:31:31 【问题描述】:
//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】:

app 具有 secureTextFields,其中包含任何带有安全文本输入的 `UITextFields'。

【讨论】:

以上是关于UITest XCUIElementQuery 缺少元素的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 XCUIElementQuery 测试 UIView 的存在?

XCUIElementQuery 将匹配自定义类的所有实例

Xcode 7 UI 测试 XCUIElementQuery 随机未正确更新

如何将expectationForPredicate 与XCUIElementQuery UISwitch 一起使用

使用 XCUIElementQuery 在 SwiftUI 中查找嵌入在表单中的 DatePicker() 的可访问性(标识符:)

Xamarin.UITest:如何检索设备显示的坐标