Skip to content
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

Closed
wants to merge 0 commits into from
Closed

Add saving screenshots in subdirectories #632

wants to merge 0 commits into from

Conversation

SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Apr 17, 2019

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
  • (and many more)

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
  • (and many more)

@facebook-github-bot
Copy link

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!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@SjorsO
Copy link
Contributor Author

SjorsO commented Apr 17, 2019

The CI fails, but the errors seem to be unrelated to my PR

Copy link
Collaborator

@OndraM OndraM left a 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';
Copy link
Collaborator

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:

Suggested change
$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);
Copy link
Collaborator

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function testShouldSaveScreenshotToFileInSubDirectory()
public function testShouldSaveScreenshotToFileAndCreateDirectory()

@OndraM
Copy link
Collaborator

OndraM commented Jun 9, 2019

Also, if you rebase the tests against community branch, the Travis builds should now be fixed.

@SjorsO
Copy link
Contributor Author

SjorsO commented Jun 30, 2019

@OndraM I've implemented your feedback, let me know if there is anything else

@OndraM
Copy link
Collaborator

OndraM commented Nov 30, 2019

Merged manually, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants