-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add saving screenshots in subdirectories #632
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
The CI fails, but the errors seem to be unrelated to my PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for the contribution! I suggest just a few improvements in the tests :)
$this->markTestSkipped('Screenshots are not supported by HtmlUnit browser'); | ||
} | ||
|
||
$screenshotPath = sys_get_temp_dir() . '/fb-webdriver/dir/selenium-screenshot.png'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure the screenshot is actually saved into newly created directory, random directory and random file name could be used:
$screenshotPath = sys_get_temp_dir() . '/fb-webdriver/dir/selenium-screenshot.png'; | |
$screenshotPath = sys_get_temp_dir() . '/' . uniqid('php-webdriver') . '/' . uniq('screenshot') '.png'; |
|
||
$this->assertFileExists($screenshotPath); | ||
|
||
unlink($screenshotPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not remove the directory after the test, only the file. This should help:
rmdir(dirname($screenshotPath));
/** | ||
* @covers ::takeScreenshot | ||
*/ | ||
public function testShouldSaveScreenshotToFileInSubDirectory() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testShouldSaveScreenshotToFileInSubDirectory() | |
public function testShouldSaveScreenshotToFileAndCreateDirectory() |
Also, if you rebase the tests against community branch, the Travis builds should now be fixed. |
@OndraM I've implemented your feedback, let me know if there is anything else |
Merged manually, thanks! |
This PR adds the ability to save screenshots in subdirectories. Currently, the directory you give to the
takeScreenshot()
method has to exist, else it will throw an exception. With this PR you can save the screenshot to a directory that does not exist, the directory will be created automatically.My use-case is that i'm working with Laravel Dusk, and i want to save screenshots for each form that the tests fill in. Currently, the screenshots all end up in the same directory, so i have to name them something like:
user-activation-single-company-step-1.png
user-activation-single-company-step-2.png
user-activation-multiple-companies-step-1.png
user-activation-multiple-companies-step-2.png
With this PR i can save them in directories instead, like this:
user-activation/single-company/step-1.png
user-activation/single-company/step-2.png
user-activation/multiple-companies/step-1.png
user-activation/multiple-companies/step-2.png