gpt4 book ai didi

java - 如何改进 WebDriver ExpectedCondition 的错误消息?

转载 作者:行者123 更新时间:2023-11-30 07:25:39 26 4
gpt4 key购买 nike

我有一个像这样的实用方法:

public void verifyTitle(int secsToWait) {
new WebDriverWait(driver, secsToWait)
.until(ExpectedConditions.titleIs(title));
}

当它失败时,消息是:

org.openqa.selenium.TimeoutException

Timed out after 2 seconds waiting for title to be: Some title here Build info: version: '2.2.1', revision: '16551', time: '2012-04-11 21:42:35' System info: os.name: 'Linux', os.arch: 'i386', os.version: '3.0.0-16-generic', java.version: '1.7.0_04' Driver info: driver.version: unknown

我找不到提供更好的错误消息的 API。我想要的是:

Timed out after 2 seconds waiting for title to be: Some title here (but the title was: Some other title)

我可以像下面介绍的那样使用 try/catch 来完成,但也许还有其他选择?

public void verifyTitle(int secsToWait) {
try {
new WebDriverWait(driver, secsToWait)
.until(ExpectedConditions.titleIs(title));
}
catch (TimeoutException e) {
throw new AssertionError(String.format("Expected page title [%s] but was [%s]", title, driver.getTitle()));
}
}

最佳答案

使用withMessage()方法:

WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.withMessage("Any message you want");
wait.until(ExpectedConditions.titleIs(title));

关于java - 如何改进 WebDriver ExpectedCondition 的错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10814807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com