为什么我的'等待方法'没有使TestNG测试用例失败?

问题描述 投票:-4回答:1

我故意更改了元素,因此它不正确,但我的测试在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);
}

enter image description here

新代码更改:

    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() + ">");
    }
}
java selenium selenium-webdriver webdriver testng
1个回答
4
投票
} catch (Exception e) {
  System.out.println("Unable to wait and click on element, Exception: " + e.getMessage());
}

您正在捕获所有异常,因此测试不会失败。

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