I’ve been working on my first substantial Laravel application recently. The application is designed to automate maintenance and testing for some of our WordPress websites.
Laravel has a lot of cool features and add-on packages, but one which was of immediate interest was Dusk.
Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK or Selenium on your machine. Instead, Dusk uses a standalone ChromeDriver installation. However, you are free to utilize any other Selenium compatible driver you wish.
Now, Dusk is mainly geared towards testing your own Laravel application. You run its tests via the Artisan CLI so it’s not really designed to be run from within the application itself.
Nevertheless it is possible – and actually not so difficult – to run your own tests and automated actions within your Laravel application. Here’s a stripped-down example of taking a full-screen screenshot – it even handles lazy-loaded images: