selenium 命令失败后创建屏幕截图
PHPUnit Selenium 基类有一个选项可以在失败时进行屏幕截图,这对于找出测试失败的原因有很大帮助。然而,除了显式的 assert*
调用(例如我们尝试对不存在的元素执行某些操作)之外的任何错误条件下,selenium 服务器都会返回错误而不是失败。如果我在服务器报告错误后尝试进行屏幕截图,则会收到另一个错误,表明服务器已丢弃会话。有什么办法可以改变这种行为吗?
更新:这是因为 PHPUnit 在收到错误时会中断连接。我能够通过对 PHPUnit 代码进行一些(相当丑陋的)操作来更改它。
The PHPUnit Selenium base class has an option to make a screenshot on failure, which is a huge help in finding out why the test failed. The selenium server, however, returns an error instead of a failure on any error condition other than explicit assert*
calls (such us trying to do something with a non-existent element). If I try to make a screenshot after the server reports the error, I get another error saying that the server already discarded the session. Is there any way to change that behavior?
Update: this is because PHPUnit breaks the connection when it receives an error. I was able to change it by some (rather ugly) manipulation of the PHPUnit code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将这些交互作为测试用例。
例如在 Perl 中,
如果如下写法,由于元素不存在而失败。脚本将错误输出,
而如果将上述步骤作为测试用例编写如下,
则如果存在不存在的元素,则测试用例只会< strong>失败,脚本将继续。
因此,通过使用模块
use Test::More;
使用 TAP(测试任何协议),如果在函数后面添加_ok
,则函数返回将用于确定测试用例的命运。IE。 - 返回“O”表示测试失败
,返回“1”表示测试通过
Make those interactions as test cases.
For example in perl,
If it is written as below and fails due to a non-existent element. the script will error out
While if the above step is made as a test case by writing it as follows
If there is a non-existent element, the test case will only fail, and the script will continue.
So using TAP (test any protocol) by using the module
use Test::More;
, if_ok
is added after a function, the function return will be used to determine the fate of the test case.ie. - A return of 'O' means the test Failed
and A return of '1' means the test Passed
它不是 Selenium 服务器,而是 PHPUnit 3.4 的
SeleniumTestCase
类,它在检测到错误时自动发送停止命令(Driver.php 第 921 行)。 PHPUnit 3.6 似乎可以更好地处理错误。It is not the Selenium server but the
SeleniumTestCase
class for PHPUnit 3.4 which automatically sends a stop command when it detects an error (Driver.php line 921). PHPUnit 3.6 seems handle errors better.我认为你可以覆盖方法“travelbox”并制作如下内容:
I think you can overwrite method 'travelbox' and make something like this: