jag*_*ggy 2 php selenium phpunit
我知道截图可以通过扩展来实现,PHPUnit_Extensions_Selenium2TestCase
但是现在,我正在使用Facebook的php-webdriver所以我只是延伸PHPUnit_Framework_TestCase
无论如何,只有驱动程序而不是扩展扩展名才能截取屏幕截图?
谢谢.
小智 5
我找到了这样的解决方案来制作失败时的屏幕截图:
/**
* {@inheritdoc}
*/
public function tearDown()
{
$status = $this->getStatus();
if ($status == \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
|| $status == \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
$now = new \DateTime('now');
$screenshotFileName = $this->getParameter('screenshots_directory_full_path');
$screenshotFileName = $screenshotFileName . $now->format('Y-m-d H:i:s') . ' test ' . $this->getName() . '.png';
$this->webDriver->takeScreenshot($screenshotFileName);
}
$this->webDriver->quit();
}
Run Code Online (Sandbox Code Playgroud)
您很久以前就问过这个问题,但希望它对其他人有帮助:)