即使是Java.lang.AssertionError:预期[true],但发现[false]



我运行时会出现此错误。我正在尝试运行它,然后更改为true,然后返回false。你知道为什么会发生吗?

public static boolean elementIsPresent(MobileElement element) {
    try {
        element.isDisplayed();
    } catch (org.openqa.selenium.NoSuchElementException e) {
        return true;
    }
    return false;
}
public void checkbox() {
    try {
        Assert.assertTrue(elementIsPresent(this.CimonCheckBox));
        Log.log(driver).info("Passes matches Cimon Name");
        Assert.assertTrue(elementIsPresent(this.KurwaCheckbox));
        Log.log(driver).info("Passes matches names");
    } catch (Exception e) {
        Assert.fail("CheckBox: " + e.getMessage());
    }
}

if语句中的逻辑是向后。如果您获得了NosuchelementException,则您将返回真实。如果您想考虑"显示"为"现在",那么我认为您的方法应该是:

public static boolean elementIsPresent(MobileElement element) {
    try {
        return element.isDisplayed();
    } catch (org.openqa.selenium.NoSuchElementException e) {
        return false;
    }
}

,或者如果您只想返回True(无论是否显示),则可以是:

 public static boolean elementIsPresent(MobileElement element) {
        try {
            element.isDisplayed();
        } catch (org.openqa.selenium.NoSuchElementException e) {
            return false;
        }
        return true;
    }

相关内容

最新更新