Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class WebTestCase extends PHPUnit_Extensions_Selenium2TestCase
- {
- protected $captureScreenshotOnFailure = TRUE;
- protected $screenshotPath = '/../../screenshots';
- protected $screenshotUrl = 'http://localhost:8080/screenshots';
- protected function setUp() {
- $this->setBrowser('phantomjs');
- $this->setBrowserUrl("http://localhost:8080");
- $this->setHost('localhost');
- }
- }
- class Test extends WebTestCase
- {
- public function testTitle()
- {
- $this->url('');
- assertEquals($this->title(), "My App");
- }
- }
- $ vendor/bin/phpunit
- PHPUnit 4.6-ge85198b by Sebastian Bergmann and contributors.
- Configuration read from /MyApp/phpunit.xml
- F
- Time: 231 ms, Memory: 5.50Mb
- There was 1 failure:
- 1) Test::testTitle
- Failed asserting that two strings are equal.
- --- Expected
- +++ Actual
- @@ @@
- -''
- +'My App'
- /MyApp/tests/functional/Test.php:7
- FAILURES!
- Tests: 1, Assertions: 1, Failures: 1.
- <?php
- class Test extends PHPUnit_Extensions_Selenium2TestCase
- {
- protected function setUp() {
- $this->setBrowser('phantomjs');
- $this->setBrowserUrl("http://localhost:8080");
- $this->setHost('localhost');
- }
- public function testEnterText()
- {
- $this->url("/");
- try {
- $this->assertEquals($this->title(), "My App");
- } catch (Exception $e) {
- $this->screenshot( __DIR__.'/'.$this->getName().'-'.time(). '.png');
- }
- }
- public function screenshot($file)
- {
- $filedata = $this->currentScreenshot();
- file_put_contents($file, $filedata);
- }
- }
- <?php
- class homepageTest extends PHPUnit_Extensions_Selenium2TestCase {
- private $listener;
- public function setUp() {
- // Your screenshots will be saved in '/var/www/vhosts/screenshots/'
- $screenshots_dir = '/var/www/vhosts/screenshots/';
- $this->listener = new PHPUnit_Extensions_Selenium2TestCase_ScreenshotListener($screenshots_dir);
- $this->setBrowser('firefox');
- $this->setBrowserUrl('https://netbeans.org');
- }
- public function tearDown() {
- $this->stop();
- }
- public function testNetbeansContainsHorses() {
- $this->url('https://netbeans.org');
- $this->assertContains('Equestrian', $this->title()); // Will fail on NetBeans page.
- }
- public function onNotSuccessfulTest($e) {
- $this->listener->addError($this, $e, null);
- parent::onNotSuccessfulTest($e);
- }
- }
- class MyBaseWebTests
- {
- $this->directory = '/some_path_to_put_screenshots_in/';
- // Override PHPUnit_Extensions_Selenium2TestCase::onNotSuccessfulTest
- public function onNotSuccessfulTest(Exception $e)
- {
- $filedata = $this->currentScreenshot();
- $file = $this->directory . get_class($this) . '.png';
- file_put_contents($file, $filedata);
- parent::onNotSuccessfulTest($e);
- }
- }
- $fp = fopen('path/35.png', 'wb');
- fwrite($fp, $this->currentScreenshot());
- fclose($fp);
- sleep(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement