I'm using PHPUnit and Selenium 2 to do some integration tests on my web app. I would like a screenshot to be saved every time a test fails. Here is what I have so far:
<?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());
}
}
This works fine, and saves a screenshot when the test is run - however, I would like to be able to save a screenshot only after a test failure, and this should happen with every test. Is there a way of telling PHPUnit to automatically run a function after every test failure?
Thanks
Try to use the method tearDown()
or onNotSuccessfulTest()
http://phpunit.de/manual/current/en/fixtures.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With