为什么我的'等待方法'没有使TestNG测试用例失败?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么我的'等待方法'没有使TestNG测试用例失败?相关的知识,希望对你有一定的参考价值。
我故意更改了元素,因此它不正确,但我的测试在TestNG中没有失败。有任何想法吗?
我的代码:
public void waitAndClickElement(WebElement element) throws InterruptedException {
try {
element.click();
} catch (TimeoutException timeEx) {
this.wait.until(ExpectedConditions.elementToBeClickable(element)).click();
} catch (StaleElementReferenceException elementUpdated) {
this.wait.until(ExpectedConditions.elementToBeClickable(element)).click();
} catch (Exception e) {
System.out.println("Unable to wait and click on element, Exception: " + e.getMessage());
}
}
@Test(priority = 2)
public void clickOnDrivingExperiencePage() throws Exception {
basePage.waitAndClickElement(homepageHeader.link_DrivingExperiences);
}
新代码更改:
public void waitAndClickElement(WebElement element) throws InterruptedException {
try {
this.wait.until(ExpectedConditions.elementToBeClickable(element)).click();
System.out.println("Successfully clicked on the WebElement: " + "<" + element.toString() + ">");
} catch (Exception e) {
System.out.println("Unable to wait and click on WebElement, Exception: " + e.getMessage());
Assert.assertFalse(true, "Unable to wait and click on the WebElement, using locator: " + "<" + element.toString() + ">");
}
}
答案
} catch (Exception e) {
System.out.println("Unable to wait and click on element, Exception: " + e.getMessage());
}
您正在捕获所有异常,因此测试不会失败。
以上是关于为什么我的'等待方法'没有使TestNG测试用例失败?的主要内容,如果未能解决你的问题,请参考以下文章