我如何在不更改默认超时的情况下将消息添加到browser.wait()?

问题描述 投票:0回答:1

我有一些代码

browser.wait(ExpectedConditions.presenceOf(elementName));

通常这会失败,只是说“预期为真,否则为假”。这确实让我大吃一惊。当它失败时,我希望它给我一个更具描述性的原因,为什么它以elementName失败。

所以我想更改它以添加一条消息。 browser.wait的定义是:

wait(condition: WebElementCondition, opt_timeout?: number, opt_message?: string): WebElementPromise;

所以我可以做:

browser.wait(ExpectedConditions.presenceOf(element), 0, `Expected presence of ${elementName}`);

但是我不想在不需要时更改opt_timeout。有什么方法可以通过opt_message而不通过opt_timeout吗?

angular typescript selenium protractor
1个回答
0
投票
browser.wait(ExpectedConditions.presenceOf(element), undefined, `Expected presence of ${elementName}`);

您可以在第二个参数中传递undefined。使用undefined不会更改默认超时。

效果很好

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.