Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 060af76

Browse files
SjorsOOndraM
authored andcommitted
Allow screenshots to be saved in subdirectory
1 parent 13fc55d commit 060af76

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Remote/RemoteWebDriver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,14 @@ public function takeScreenshot($save_as = null)
373373
$screenshot = base64_decode(
374374
$this->execute(DriverCommand::SCREENSHOT)
375375
);
376+
376377
if ($save_as) {
378+
$directoryPath = dirname($save_as);
379+
380+
if (!file_exists($directoryPath)) {
381+
mkdir($directoryPath, 0777, true);
382+
}
383+
377384
file_put_contents($save_as, $screenshot);
378385
}
379386

tests/functional/RemoteWebDriverTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ public function testShouldSaveScreenshotToFile()
257257
$this->markTestSkipped('Screenshots are not supported by HtmlUnit browser');
258258
}
259259

260-
$screenshotPath = sys_get_temp_dir() . '/selenium-screenshot.png';
260+
// Intentionally save screenshot to subdirectory to tests it is being created
261+
$screenshotPath = sys_get_temp_dir() . '/' . uniqid('php-webdriver-') . '/selenium-screenshot.png';
261262

262263
$this->driver->get($this->getTestPageUrl('index.html'));
263264

@@ -270,6 +271,7 @@ public function testShouldSaveScreenshotToFile()
270271
$this->assertGreaterThan(0, imagesy($image));
271272

272273
unlink($screenshotPath);
274+
rmdir(dirname($screenshotPath));
273275
}
274276

275277
/**

0 commit comments

Comments
 (0)