laravel / dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
https://laravel.com/docs/dusk
MIT License
1.87k stars 320 forks source link

New Helper `elementScreenshot` #1093

Closed rabrowne85 closed 5 months ago

rabrowne85 commented 5 months ago

Expanding on the existing helpers for screenshot and responsiveScreenshots this new helper is for taking a screenshot of a specific element, by passing in the $selector for the element and then using the takeElementScreenshot() method of the RemoteWebElement::class.

As the element needs to be 'in view' before the screenshot can be taken, the helper first calls scrollIntoView before taking the screenshot.

Of course, the same could be achieved by adding a Browser::macro in the service provider, but this pull request would put it alongside the existing methods and include in the package.

Tests have been included that follow a similar pattern as those for the screenshot method.