【问题标题】:UI testing - No matches found for Descendants matching type... recording generated codeUI 测试 - 没有找到匹配类型的后代的匹配项...记录生成的代码
【发布时间】:2018-05-14 18:54:56
【问题描述】:

我收到一个错误

No matches found for Find: Descendants matching type NavigationBar from input {( Application, 0x60400019b790, pid: 20515, label: '<appname>' )}

但是代码是由 XCUITest 的录制功能生成的,所以我不明白为什么它找不到导航栏。我添加了一个accessibilityIdentifier,它是一个名为dashboardNavBar 的本地化字符串,尝试使用它来查找它,但我无法查询它。我正在使用的当前代码是:

func testLoginLogout() {
    let app = XCUIApplication()
    //login credentials and other code that takes me to dashboard of app
    app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
    app.sheets["Do you want to Logout ?"].buttons["OK"].tap()
}

app.navigationBars... 行是引发上述错误的行。我希望有人能告诉我为什么它无法找到此导航栏或任何问题,以及如何使用accessibilityIdentifier 修复它或解决它。谢谢。

【问题讨论】:

  • 记录的代码说你要点击的元素是一个按钮。您可以像 app.buttons["AccessibilityID"].tap() 一样直接点击该按钮。否则你可以通过调试模式找到它并输入 po app.buttons.debugdescription |然后它将打印所有按钮。然后你也可以通过 app.buttons.element(boundBy : indexofSpecificelement).tap() 访问元素。让我知道你的发现。

标签: ios swift xctest xcuitest


【解决方案1】:

我知道这可能是一种解决方法,而不是真正的解决方案,但是当我遇到此问题时,我所做的是添加检查元素是否存在并尝试两次运行相同的操作。当您在此操作之后进行 segue 时,该元素不应该存在,并且不会执行第二次调用尝试。例如:

    func testLoginLogout() {
            let app = XCUIApplication()
            if (app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).exists) {
                app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
            }
// and if you will call it again the element should not exists, otherwise it will be called again

            if (app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).exists) {
                app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
            }

            if (app.sheets["Do you want to Logout ?"].buttons["OK"].exists) {
                app.sheets["Do you want to Logout ?"].buttons["OK"].tap()
            }
        }

【讨论】:

    猜你喜欢
    • 2018-08-13
    • 2016-03-30
    • 2016-03-07
    • 2016-04-14
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    相关资源
    最近更新 更多