Documentation
Web Browser Automation
Automate a real browser from your Artisan commands with Laravel Dusk
On this page
Introduction#
Laravel Dusk provides an expressive, easy-to-use browser automation API. In Laravel, it is used for testing. In a console application, it is a great way to automate web tasks — scraping a page, filling out a form, or taking a screenshot on a schedule.
The console-dusk component makes Laravel Dusk available inside your Artisan commands.
Installation#
You may install the console-dusk component using the app:install Artisan command:
php application app:install console-dusk
Browsing From a Command#
Once the component is installed, your commands have access to the browse method. It accepts a closure that receives a browser instance:
<?php namespace App\Commands; use LaravelZero\Framework\Commands\Command; class VisitLaravelZeroCommand extends Command { protected $signature = 'visit'; protected $description = 'Visit the Laravel Zero website'; public function handle(): void { $this->browse(function ($browser) { $browser->visit('https://laravel-zero.com') ->assertSee('Laravel Zero'); }); } }
Running the command will drive a real browser:
The full browser API — clicking links, filling forms, waiting for elements, and taking screenshots — is documented in the Dusk documentation on the Laravel website.
Note: Behind the scenes, this component uses the
nunomaduro/laravel-console-duskpackage. You will find further details there.
Spotted a mistake? Edit this page on GitHub.