I think my issue has nothing to do with code but with waiting for UI-Elements in tests in general or at least my understanding of testing UIs with JUnit and Selenium/Arquillian Graphene.
When using Arquillian Graphenes waitModel() (or any of the other methods waiting for UI-Elements) and the element is not present after the specified timeout, I get a seleniumTimeoutException, which lets my JUnit-Test end with an "Error".
ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 151.709 s <<< FAILURE! - in de.viasurance.UiTest
[ERROR] testHappyPath(org.test1.UiTest) Time elapsed: 23.266 s <<< ERROR!
org.openqa.selenium.TimeoutException:
Is there a better way to let the test end with a "Failure" without surrounding every single line of my test with a try/catch-block like this:
try {
waitModel().withMessage("waiting for loginButton").until().element(loginButton).is().clickable();
} catch (TimeoutException timeoutException) {
fail("UI-Test failed because the following UI-element could not be found: \n" + timeoutException.getMessage());
}
You do NOT have to surround this with a try/catch block and fail in the catch block
That should be taken care by your test framework itself. TestNG does a good job here.
For Junit, You could use TestWatcher to detect the error and fail accordingly.