kgress / scaffold

A Java based Selenium WebDriver abstraction
MIT License
4 stars 7 forks source link

BaseWebElement.isDisplayed()/others throws exception instead of returning false #111

Closed Proryanator closed 2 years ago

Proryanator commented 2 years ago

Bug

The original behavior of BaseWebElement.isDisplayed() was to return true/false for whether an element was displayed or not, to allow a quick check of whether an element is there. Any WebDriverException would be caught and return as false. See the old renamed class here:

Screen Shot 2021-12-14 at 3 23 30 PM

This was changed to just returning getRawWebElement().isDisplayed() which is no longer handling the exceptions thrown from getRawWebElement() and effectively making isDisplayed() only ever return true or throw an exception.

See the current code linked here with a screenshot below: Screen Shot 2021-12-14 at 3 28 27 PM

This also applies to other methods that return booleans, that first call getRawWebElement() such as hasClass(), isEnabled(), isActive() for example, these would also need to catch exceptions and return true/false.

Expected

I think this should be wrapped up again to return false if a WebDriverException occurs, as that's the typical expected behavior and how it's mostly used.

// used in decision making, unless fixed will throw an exception and prevent clean decision handling
if (element.isDisplayed()){
   // do the thing with this element
}

// used in assertions, right now would throw an exception that needs to be handled which makes code messier
assertTrue(page.getElement().isDisplayed(), "Element was not displayed");