让 javascript 强制 Selenium 测试失败

发布于 2024-07-20 02:45:13 字数 344 浏览 4 评论 0原文

有没有办法让 js 代码强制 Selenium 测试失败? 对于(可能是坏的)示例,如果我有以下内容:

return document.getElementById('foo').innerHTML == 'hello'

有没有办法让“runScript”命令失败,具体取决于 js 代码返回 true 还是 false? (我知道其他 Selenium 命令可以使用该示例,但我想要一个更通用的解决方案。)

我是否需要学习如何扩展 Selenium 以添加另一个命令?

我对 Selenium 也比较陌生,所以使用 Selenium-rc 可以解决这个问题吗?

Is there a way for js code to force Selenium testing to fail? For (a probably bad) example, if I had the following:

return document.getElementById('foo').innerHTML == 'hello'

is there a way I could make the 'runScript' command fail depending on if the js code returned true or false? (I know that example could be used by other Selenium commands, but I wanted a more general solution.)

Do I need to learn how to extend Selenium to add another command?

I'm also relatively new to Selenium so is this something that using Selenium-rc will solve?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

溺渁∝ 2024-07-27 02:45:13

assertExpression 会给你你所要求的。

例如,如果您提到的 JavaScript 表达式的计算结果不为 true,则以下行将导致您的测试失败。

<tr>
<td>assertExpression</td>
<td>javascript{this.browserbot.getCurrentWindow().document.getElementById('foo').innerHTML == 'hello'}</td>
<td>true</td>
</tr>

assertExpression will give you what you're asking for.

For instance, the following line would cause your test to fail if the JavaScript expression you mention did not evaluate to true.

<tr>
<td>assertExpression</td>
<td>javascript{this.browserbot.getCurrentWindow().document.getElementById('foo').innerHTML == 'hello'}</td>
<td>true</td>
</tr>
李不 2024-07-27 02:45:13

这取决于您想如何使用硒。 在selenese套件中,有对verifyText等的调用(只需谷歌搜索selenese套件和verifyText,waitForCondition)。 如果您在例如java中使用selenium远程控制,那么您可以在java代码中进行断言。 使用远程控制,您可以将脚本发送到页面,然后您可以获取代码评估返回的内容。 比较/断言是在 java 客户端中完成的。

It depends how you want to use selenium. In selenese suite there are calls for verifyText, etc (just google for selenese suite and verifyText, waitForCondition). If you are using the selenium remote control in e.g. java than you do the assertions in the java code. With the remote control you send scripts to the page and you get back what the evaluation of the code returns. The comparsion/assertion is done in the java client.

静赏你的温柔 2024-07-27 02:45:13

评估('asdfklj;'); //硒击中了它。 老实说我自己从来没有使用过它。 需要尽快学习它,但我假设它可以解决 javascript 错误。

eval('asdfklj;'); //Selenium Hits it. Honestly I've never used it myself. Need to learn it soon, but I'm assuming it can bomb do to javascript errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文