【问题标题】:Get success on UITest when waitForExpectations failswaitForExpectations 失败时在 UITest 上取得成功
【发布时间】:2017-11-20 02:59:37
【问题描述】:

如果预期元素(在我的情况下为警报)在超时之前(根据服务器请求)未出现,我有一项任务要成功通过 UITest。

代码:

let element = app.alerts["test text"]
let existsPredicate = NSPredicate(format: "exists == true")
expectation(for: existsPredicate, evaluatedWith: element, handler: nil)

waitForExpectations(timeout: 10, handler: nil)

// when timeout expired test should finish with success

没有通过 Internet 找到任何解决方案。

【问题讨论】:

    标签: ios swift xcode-ui-testing uitest


    【解决方案1】:

    Оооо,你应该注意它是UITest。在这种情况下,期望具有很好的属性:isInverted。将此设置为 true,表示预期不会发生。 )))

    let element = app.alerts["test text"]
    let existsPredicate = NSPredicate(format: "exists == true")
    let expectation = expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
    expectation.isInverted = true // if alert doesn't appear during 10 seconds, then test passed
    
    waitForExpectations(timeout: 10, handler: nil)
    

    【讨论】:

    • 太棒了!这正是我所需要的!谢谢你提供这个线索!邮政编码,我会接受你的回答。
    • 我自己添加的。请删除之前的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 2019-06-30
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多