ScreenshotTest.php 807 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Basic;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class ScreenshotTest extends TestCase
  5. {
  6. public function testScreenshot()
  7. {
  8. if (!extension_loaded('gd')) {
  9. $this->markTestSkipped('Testing screenshots requires the GD extension');
  10. }
  11. $this->getSession()->visit($this->pathTo('/index.html'));
  12. $screenShot = $this->getSession()->getScreenshot();
  13. $this->assertInternalType('string', $screenShot);
  14. $this->assertFalse(base64_decode($screenShot, true), 'The returned screenshot should not be base64-encoded');
  15. $img = imagecreatefromstring($screenShot);
  16. if (false === $img) {
  17. $this->fail('The screenshot should be a valid image');
  18. }
  19. imagedestroy($img);
  20. }
  21. }