Arquillian石墨烯等待模型超时异常让测试以错误而不是失败结束



我认为我的问题与代码无关,而是与在一般测试中等待UI-Elements有关,或者至少我对使用JUnit和Selenium/Arquillian Graphene测试UI的理解。

当使用Arquillian Graphenes waitModel()(或任何其他等待UI-Elements的方法)并且元素在指定的超时后不存在时,我得到一个seleniumTimeoutException,它让我的JUnit-Test以"错误"结束。

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: 

有没有更好的方法可以让测试以"失败"结束,而不会用这样的 try/catch-block 包围我测试的每一行:

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());
}

您不必用 try/catch 块将其包围并在 catch 块中失败

这应该由测试框架本身来处理。TestNG在这方面做得很好。

Graphene.waitModel()
.withMessage("Login Button Not clickable")
.until()
.element(loginButton)
.is()
.clickable();

对于 Junit,您可以使用 TestWatcher 来检测错误并相应地失败。

相关内容

最新更新