我故意更改了元素,因此它不正确,但我的测试在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());
}
您正在捕获所有异常,因此测试不会失败。