Laravel Dusk provides an easy-to-use browser automation using chromedriver installation.
Install composer dependency for your application
composer require --dev laravel/dusk
Now execute below artisan command
php artisan dusk:install
Set the APP_URL env variable in the .env file. This value should match the URL you use to access your application in a browser.
Create a test
php artisan dusk:make HomepageTest
<?php
namespace Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
class HomepageTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* @return void
*/
public function testExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}
}
Run test
php artisan dusk
This will run the test and open up a chrome browser for you.
$ php artisan dusk
The output of the test case will be displayed as below:
$ php artisan dusk
Warning: TTY mode is not supported on Windows platform.
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
DevTools listening on ws://127.0.0.1:58022/devtools/browser/ef759107-543f-4e4c-b862-5bde5c43549b
.
DevTools listening on ws://127.0.0.1:58047/devtools/browser/52c0fb65-4104-4b18-9741-58c235811e54
. 2 / 2 (100%)
Time: 00:05.610, Memory: 22.00 MB
OK (2 tests, 2 assertions)