Assertion失败时如何继续执行 [英] How to continue execution when Assertion is failed
问题描述
我使用Selenium RC使用Java与eclipse和TestNG框架。我有以下代码片段:
I am using Selenium RC using Java with eclipse and TestNG framework. I have the following code snippet:
assertTrue(selenium.isTextPresent("Please enter Email ID"));
assertTrue(selenium.isTextPresent("Please enter Password"));
第一个断言失败,执行停止。但是我想继续进一步的代码片段。
First assertion was failed and execution was stopped. But I want to continue the further snippet of code.
推荐答案
Selenium IDE使用verify来执行软断言,这意味着测试即使检查失败也会继续,并在测试结束时或在硬判断事件中报告失败。
Selenium IDE uses verify to perform a soft assertion, meaning that the test will continue even if the check fails and either report the failures at the end of the test or on the event of a hard assertion.
使用TestNG可以使用这些通过使用自定义测试侦听器进行软断言。我已经记录了如何在我的博客上执行此操作: http://davehunt.co.uk/2009/10/08/using-soft-assertions-in-testng.html
With TestNG it is possible to have these soft assertions by using custom test listeners. I have documented how to do this on my blog: http://davehunt.co.uk/2009/10/08/using-soft-assertions-in-testng.html
基本上,你需要创建自己的验证*
方法,在这些方法中,您可以捕获断言失败并将它们添加到地图中。然后在自定义 afterInvocation
侦听器中,如果地图不为空,则可以将测试设置为失败。
Basically, you need to create your own verify*
methods, in these you can catch assertion failures and add them to a map. Then in a custom afterInvocation
listener you can set the test to failed if the map is not empty.
这篇关于Assertion失败时如何继续执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!