I want to test a feature that requires a pageload to be updated. Since selenide only checks if the element has appeared without reloading the page, it will not pick up on the updated state.
I am currently doing it like this:
element(byAttribute("type", "submit")).click()
try {
element(byText("some specific text")).shouldBe(visible)
} catch (e: com.codeborne.selenide.ex.ElementNotFound){
refresh()
element(byText("some specific text")).shouldBe(visible)
}
This is bad in multiple ways:
- it catches an error, which is not intended to be caught (otherwise it would have been an exception)
- it triggers side effects, like creating error-screenshots
- it only retries exactly once
- it waits the full first timeout, which may not even be needed. e.g. maybe it could have refreshed immediately then be successful
in case you are wondering: the feature in question is related to a cache being warm or cold. Forcing the cache to be cold at the beginning of the test would probably be possible, but it would also add a lot of complexity (e.g. interacting directly with the database), which I would like to avoid.