断言失败时如何继续执行 [英] How to continue execution when Assertion is failed

查看:65
本文介绍了断言失败时如何继续执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 Eclipse 和 TestNG 框架的 Java 的 Selenium RC.我有以下代码片段:

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

基本上,您需要创建自己的 verify* 方法,在这些方法中您可以捕获断言失败并将它们添加到映射中.然后在自定义 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.

这篇关于断言失败时如何继续执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆