【问题标题】:Custom message on wait timeout error等待超时错误的自定义消息
【发布时间】:2015-03-11 05:41:18
【问题描述】:

我不时使用在 protractor 1.7 中引入的"Expected Conditions" feature。

用例:

var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(header.displayName), 10000);

其中header 是一个页面对象。

如果header.displayName 在 10 秒内不可见,则会抛出错误:

[firefox #4]   2) Describe description here
[firefox #4]    Message:
[firefox #4]      Error: Wait timed out after 10082ms
[firefox #4]    Stacktrace:
[firefox #4]      Error: Wait timed out after 10082ms
[firefox #4] ==== async task ====
[firefox #4]     at [object Object].<anonymous> (/Path/to/project/test/e2e/my.spec.js:38:17)

这不是很可读,需要一些时间来理解和一些研究。

问题:

是否可以自定义这种等待超时错误?


仅供参考,我们可以提供自定义的expect 失败消息,如下所述:

【问题讨论】:

    标签: testing selenium jasmine protractor end-to-end


    【解决方案1】:

    我相信browser.wait() 需要 3 个参数:条件、可选超时和可选描述消息。 (我很确定这是文档:http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.wait,但我很难验证 WebDriver 在量角器中是否显示为browser)。所以你应该能够做到:

    var EC = protractor.ExpectedConditions;
    var timeoutMS = 10 * 1000;
    var timeoutMsg = "Waiting for header displayName";
    browser.wait(EC.visibilityOf(header.displayName), timeoutMS, timeoutMsg);
    

    【讨论】:

    • 就是这样,不敢相信它是内置的,非常方便。再次感谢!
    猜你喜欢
    • 2013-05-29
    • 1970-01-01
    • 2021-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2011-05-13
    相关资源
    最近更新 更多