等待超时错误的自定义消息
Custom message on wait timeout error
有时我会使用量角器 1.7 中引入的 。
用例:
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
失败消息,如下所述:
- Print message on expect() assert failure
我相信 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);
有时我会使用量角器 1.7 中引入的
用例:
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
失败消息,如下所述:
- Print message on expect() assert failure
我相信 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);