Skip to content

Commit

Permalink
Dev: Catch exception if no screenshot can be taken (tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Nov 23, 2017
1 parent b3caa5c commit ac977eb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ls\tests;

use PHPUnit\Framework\TestCase;
use Facebook\WebDriver\Exception\NoSuchDriverException;

class TestHelper extends TestCase
{
Expand Down Expand Up @@ -300,10 +301,14 @@ public function takeScreenshot($webDriver, $name)
{
$tempFolder = \Yii::app()->getBasePath() .'/../tests/tmp';
$folder = $tempFolder.'/screenshots/';
$screenshot = $webDriver->takeScreenshot();
$filename = $folder . $name . date('YmdHis') . '.png';
$result = file_put_contents($filename, $screenshot);
$this->assertTrue($result > 0, 'Could not write screenshot to file ' . $filename);
try {
$screenshot = $webDriver->takeScreenshot();
$filename = $folder . $name . date('YmdHis') . '.png';
$result = file_put_contents($filename, $screenshot);
$this->assertTrue($result > 0, 'Could not write screenshot to file ' . $filename);
} catch (NoSuchDriverException $ex) {
// No driver.
}
}

/**
Expand Down

0 comments on commit ac977eb

Please sign in to comment.