PHPUnit Selenium captureScreenshotOnFailure 不起作用?
我正在使用 PHPUnit 3.4.12 来驱动我的硒测试。我希望能够在测试失败时自动截取屏幕截图。这应该得到支持,如 http 中所述://www.phpunit.de/manual/current/en/selenium.html#selenium.seleniumtestcase.examples.WebTest2.php
class WebTest
{
protected $captureScreenshotOnFailure = true;
protected $screenshotPath = 'C:\selenium';
protected $screnshotUrl = 'http://localhost/screenshots';
public function testLandingPage($selenium)
{
$selenium->open("http://www.example.com");
$selenium->fail("fail");
...
}
}
如您所见,我正在使测试失败,理论上当它失败时它应该截取屏幕截图并将其放在 C:\selenium 中,因为我在 Windows 上运行 selenium RC 服务器。
但是,当我运行测试时,它只会给出以下内容:
[root@testbox selenium]$ sh run
PHPUnit 3.4.12 by Sebastian Bergmann.
F
Time: 8 seconds, Memory: 5.50Mb
There was 1 failure:
1) WebTest::testLandingPage
fail
/home/root/selenium/WebTest.php:32
FAILURES!
Tests: 1, Assertions: 0, Failures: 1.
我在 C:\selenium 中没有看到任何屏幕截图。不过,我可以使用 $selenium->captureScreenshot("C:/selenium/image.png"); 获取屏幕截图
欢迎任何想法或建议。
谢谢
I am using PHPUnit 3.4.12 to drive my selenium tests. I'd like to be able to get a screenshot taken automatically when a test fails. This should be supported as explained at http://www.phpunit.de/manual/current/en/selenium.html#selenium.seleniumtestcase.examples.WebTest2.php
class WebTest
{
protected $captureScreenshotOnFailure = true;
protected $screenshotPath = 'C:\selenium';
protected $screnshotUrl = 'http://localhost/screenshots';
public function testLandingPage($selenium)
{
$selenium->open("http://www.example.com");
$selenium->fail("fail");
...
}
}
As you can see, I am making the test to fail and in theory when it does it should take a screenshot and put it in C:\selenium, as I am running the selenium RC server on Windows.
However, when I run the test it will just give me the following:
[root@testbox selenium]$ sh run
PHPUnit 3.4.12 by Sebastian Bergmann.
F
Time: 8 seconds, Memory: 5.50Mb
There was 1 failure:
1) WebTest::testLandingPage
fail
/home/root/selenium/WebTest.php:32
FAILURES!
Tests: 1, Assertions: 0, Failures: 1.
I do not see any screenshot in C:\selenium. I can however get a screenshot with $selenium->captureScreenshot("C:/selenium/image.png");
Any ideas or suggestions most welcome.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
phpunit 的错误处理相当差;如果一切都不完美,它会默默地忽略您的其他选项,而不发出警告。
正如 Dave 提到的,如果任何变量拼写错误,它将默默地不起作用,您也可以尝试将它们分配给设置中的实例。
此外,并非所有条件都会触发屏幕截图。尝试使用 $selenium->assertTextPresent("foobarbaz") 而不是 $selenium->fail() 进行健全性检查。
The error handling of this is rather poor on phpunit's part; if everything isn't perfect it will silently ignore your other options without a warning.
As Dave mentioned, if any of the variables are misspelled it will silently not work, and you might also try assigning them to the instance in your setUp.
Also, not every condition triggers a screenshot. Try $selenium->assertTextPresent("foobarbaz") instead of your $selenium->fail() for a sanity check.
你可以尝试添加这行代码
you may try adding these line of codes
我最近遇到了这个错误,因为我正在遵循教程。
文档中的第一个示例适用于
PHPUnit_Extensions_Selenium2TestCase
。页面上的所有其他内容均适用于 PHPUnit_Extensions_SeleniumTestCase。或许
改成
I recently had this error because I was following the tutorial.
The first example in the documentation is for
PHPUnit_Extensions_Selenium2TestCase
. All of the others on the page are forPHPUnit_Extensions_SeleniumTestCase
.Perhaps change
to