Xceptance / neodymium-library

A test automation library based on common other best practice open source libraries. It adds missing functionalities but does not reinvent the wheel. Just glues stuff together nicely and adds some sprinkles.
MIT License
80 stars 11 forks source link

Improve catching of StaleElementReferenceException #181

Closed oomelianchuk closed 3 months ago

oomelianchuk commented 3 years ago

Sometimes StaleElementReferenceException is not contained in the exception cause but only in the exception message, like in the example below:

Element should be visible {#reset-password-email}
Element: '<input aria-describedby="emailHelp" class="form-control" id="reset-password-email" name="loginEmail" placeholder="Email" type="email" value displayed:StaleElementReferenceException: stale element reference: element is not attached to the page document>StaleElementReferenceException: stale element reference: element is not attached to the page document</StaleElementReferenceException: stale element reference: element is not attached to the page document>'
Actual value: StaleElementReferenceException: stale element refe
Screenshot: file:/home/olha/git/test-automation/build/reports/tests/1619597891473.2.png
Page source: file:/home/olha/git/test-automation/build/reports/tests/1619597891473.2.html

Please think about improving the SelenideAddons.$safe method to catch SERE also in this case.

oomelianchuk commented 3 years ago

The problem is that SERE takes place while Selenide tries to get the actual visibility value. That's why the cause for both. really failed should assertion and one with SERE is null. The stack trace is also the same:

  com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java: 94),
  com.codeborne.selenide.commands.Should.execute(Should.java: 30),
  com.codeborne.selenide.commands.Should.execute(Should.java: 14),
  com.codeborne.selenide.commands.Commands.execute(Commands.java: 153),
  com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java: 104),
  com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java: 70),
  com.sun.proxy.$Proxy36.shouldBe(UnknownSource),

The only difference between these exceptions is that one with SERE contains Actual value: StaleElementReferenceException: stale element refe instead of actual value. Checking for this text in the exception message could be the way to improve the SelenideAddons.$safe method. As the text we would look for is more specific than StaleElementReferenceException, the probability of catching the wrong exception is low.

occupant23 commented 3 years ago

Ready for final test.