Browser Tests (Laravel Dusk)
Introduction
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.
Installation
To get started, you should add the laravel/dusk
Composer dependency to your project:
composer require --dev laravel/dusk:"^4.0"
Once Dusk is installed, you should register the Laravel\Dusk\DuskServiceProvider
service provider. Typically, this will be done automatically via Laravel's automatic service provider registration.
If you are manually registering Dusk's service provider, you should never register it in your production environment, as doing so could lead to arbitrary users being able to authenticate with your application.
After installing the Dusk package, run the dusk:install
Artisan command:
php artisan dusk:install
A Browser
directory will be created within your tests
directory and will contain an example test. Next, set the APP_URL
environment variable in your .env
file. This value should match the URL you use to access your application in a browser.
To run your tests, use the dusk
Artisan command. The dusk
command accepts any argument that is also accepted by the phpunit
command:
php artisan dusk