【发布时间】:2013-10-10 02:45:56
【问题描述】:
我正在使用 PHPUnit 和 Selenium 2 对我的 Web 应用程序进行一些集成测试。我希望每次测试失败时都保存一个屏幕截图。这是我目前所拥有的:
<?php
include 'c:/wamp/www/testarea/selenium/phpunit-selenium/vendor/autoload.php';
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.google.com/');
}
public function testTitle()
{
$this->url('http://www.google.com/');
file_put_contents("c:/wamp/www/testarea/selenium/phpunit-selenium/screenshots/screenshot1.png",$this->currentScreenshot());
$this->assertEquals('NOT GOOGLE', $this->title());
}
}
这可以正常工作,并在测试运行时保存屏幕截图 - 但是,我希望能够仅在测试失败后保存屏幕截图,并且每次测试都会发生这种情况。有没有办法告诉 PHPUnit 在每次测试失败后自动运行一个函数?
谢谢
【问题讨论】:
标签: php phpunit selenium-webdriver