【发布时间】:2011-02-20 06:45:53
【问题描述】:
我正在使用 PHPUnit 3.4.12 来驱动我的 selenium 测试。我希望能够在测试失败时自动截取屏幕截图。这应该得到支持,如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");
欢迎任何想法或建议。
谢谢
【问题讨论】:
-
怀疑这是问题的原因,但您的
$screnshotUrl变量应该是$screenshotUrl吗? -
@Dave Hunt:说得好,是的,这确实可能是原因,因为必须填写 $this->screenshotUrl 才能触发捕获。
标签: selenium phpunit selenium-rc screen-capture