Why is my 'Wait method' not failing the Te

2019-09-22 05:10发布

I have purposely changed the element so it is incorrect, but my test doesn't fail in TestNG. Any ideas?

My Code:

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);
}

enter image description here

New Code Changes:

    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() + ">");
    }
}

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-22 05:27
} catch (Exception e) {
  System.out.println("Unable to wait and click on element, Exception: " + e.getMessage());
}

You are catching all exceptions, so the test won't fail.

查看更多
登录 后发表回答