为什么我的“等待方法"没有通过TestNG测试用例? [英] Why is my 'Wait method' not failing the TestNG test case?

查看:152
本文介绍了为什么我的“等待方法"没有通过TestNG测试用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有意更改了元素,因此它是不正确的,但是我的测试在TestNG中没有失败.有任何想法吗?

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

我的代码:

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

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

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

这篇关于为什么我的“等待方法"没有通过TestNG测试用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆