为什么Selenium Python测试看起来很奇怪?

时间:2010-07-13 07:09:02

标签: python selenium

我已经使用Selenium IDE为我的应用程序生成一些测试代码。生成的断言Python代码如下所示。

    try: self.failUnless(sel.is_text_present("Path"))
    except AssertionError, e: self.verificationErrors.append(str(e))

不是快速失败,而是将错误添加到列表中,然后脚本继续运行。

我想知道这个的基本原理是什么?快速失败不是更好吗?或者这会使页面处于不一致状态吗?

1 个答案:

答案 0 :(得分:6)

这是Selenium中verifyassert之间的差异。使用verify时,将记录任何故障,但测试将继续,它们实际上是一个“软断言”。如果您想在失败时停止执行测试,请尝试使用assert

//verifyTextPresent
try: self.failUnless(sel.is_text_present("My Text"))
except AssertionError, e: self.verificationErrors.append(str(e))

//assertTextPresent
self.failUnless(sel.is_text_present("My Text"))