From time to time I'm using "Expected Conditions" feature introduced in protractor 1.7.
Use case:
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(header.displayName), 10000);
where header
is a Page Object.
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.
Question:
Is it possible to customize this kind of a wait timeout error?
FYI, we can provide custom expect
failure messages as described here:
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);
来源:https://stackoverflow.com/questions/28979368/custom-message-on-wait-timeout-error