等待超时错误的自定义消息 [英] Custom message on wait timeout error

查看:114
本文介绍了等待超时错误的自定义消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用量角器1.7中引入的预期条件功能

From time to time I'm using "Expected Conditions" feature introduced in protractor 1.7.

用例

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

其中 header 是一个Page Object。

where header is a Page Object.

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

If header.displayName would not become visible in 10 seconds, an error would be thrown:

[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)

哪个不太可读,需要一些时间来理解和进行一些研究。

Which is not quite readable and require some time to understand and a bit of a research.

问题:

是否可以自定义此类等待超时错误?

Is it possible to customize this kind of a wait timeout error?

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

FYI, we can provide custom expect failure messages as described here:

  • Print message on expect() assert failure

推荐答案

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

I believe browser.wait() takes 3 parameters: a condition, an optional timeout, and an optional description message. (I'm pretty sure this is the doc: http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.wait, but I'm having a hard time verifying that the WebDriver shows up as browser in protractor). So you should be able to do:

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

这篇关于等待超时错误的自定义消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆