Selenium RC测试在verifyTrue失败时通过(selenium.isTextPresent("string"))

Fea*_*nor 3 selenium-rc

我有一套Selenium测试,我在Selenium IDE中创建并移植到Java.在几个测试中,我使用verifyTextPresent命令的Java等价物来确认页面上的一些文本(verifyTrue(selenium.isTextPresent())).

从IDE运行测试时,我在页面上的文本中发现了拼写错误,但是在通过Selenium RC/TestNG运行测试时未捕获到错误.这是我的代码示例和导致问题的文本(拼写错误以粗体显示):

文本:

请更正下面指出的错误.

您需要添加一个至少一个约束.

IDE:

verifyTextPresent | Please correct the errors indicated below.
verifyTextPresent | You need to add at least one restriction.
Run Code Online (Sandbox Code Playgroud)

Java的:

verifyTrue(selenium.isTextPresent("Please correct the errors indicated below."));
verifyTrue(selenium.isTextPresent("You need to add at least one restriction."));
Run Code Online (Sandbox Code Playgroud)

由于测试的两个版本都有正确的文本,为什么Selenium RC版本没有捕获错误?有没有其他人有这个问题?

Fea*_*nor 5

发生这种情况的原因是在调用之后测试继续运行verifyTrue().Selenium中的验证捕获了验证失败所引发的异常,而不是抛出异常并导致测试失败的断言.因为验证捕获异常而不是抛出异常,所以测试通过.

在测试结束时,checkForVerificationErrors()需要调用该方法以查看是否有任何验证失败.如果未调用该方法,则将忽略任何验证错误,并且测试仍将通过(没有任何其他问题).

有关错误本身的Selenium Google Group的讨论就在这里.关于各种验证与断言的讨论在这里.