gpt4 book ai didi

ios - UI 测试 - 未找到与后代匹配类型匹配的匹配项...记录生成的代码

转载 作者:行者123 更新时间:2023-12-01 15:28:49 25 4
gpt4 key购买 nike

我收到一个错误
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... line 是引发上述错误的行。我希望有人能告诉我为什么它无法找到这个导航栏或任何问题,以及我如何使用 accessibilityIdentifier 修复它或解决它。 .谢谢。

最佳答案

我知道这可能是一种解决方法,而不是真正的解决方案,但是当我遇到此问题时,我所做的是添加了检查元素是否存在并尝试两次运行相同操作的方法。当您在此操作后进行 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()
}
}

关于ios - UI 测试 - 未找到与后代匹配类型匹配的匹配项...记录生成的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47580331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com