【问题标题】:iOS Swift UI Test tap alert buttoniOS Swift UI 测试点击警报按钮
【发布时间】:2019-10-02 22:11:10
【问题描述】:

尝试点击警报按钮时,一个非常小的 UI 测试失败,我错过了哪一步?

我正在尝试使用以下代码(我从recording my steps 获得)点击下面显示的警报中的“继续”按钮。

let app = XCUIApplication()
let salesforceloginbuttonButton = app.buttons["salesforceLoginButton"]
salesforceloginbuttonButton.tap()

let posWantsToUseSalesforceComToSignInAlert = app.alerts["“POS” Wants to Use “salesforce.com” to Sign In"]
let continueButton = posWantsToUseSalesforceComToSignInAlert.buttons["Continue"]
continueButton.tap()

当我运行测试时,它在最后一行(即:continueButton.tap())失败,错误为No matches found for Find: Descendants matching type Alert from input

注意事项:

  • 我已经尝试等待几秒钟,然后点击继续按钮,结果相同。
  • 运行测试时,应用程序启动并在点击salesforceloginbuttonButton 后显示警报

【问题讨论】:

    标签: ios swift salesforce xcode-ui-testing


    【解决方案1】:

    我认为您的警报未被识别,可能是因为双引号

    您可以尝试像这样明确设置警报的标识符:

    let alert = UIAlertController(title: "Alert", message: "msg", preferredStyle: .alert)
    alert.view.accessibilityIdentifier = "myAlert"
    

    然后在你的测试中:

    let alert = app.alerts["myAlert"]
    let button = alert.buttons["Continue"]
    button.tap()
    

    【讨论】:

    • 嗨 Alfonse,很遗憾我无法控制设置 accessibilityIdentifier 的警报。我明白你的意思,但是当应用程序中显然有警报时,它就像没有警报一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    相关资源
    最近更新 更多