Level-5; Sheikh Hasina Software Technology Park, Jessore, Bangladesh

Install Laravel Dusk

Read all about software development and Coding

Install Laravel Dusk

Installing Dusk requires a couple of steps:

composer require laravel/dusk

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

First, we will scaffold an authentication workflow using Laravel’s pre-built authentication mechanism.

php artisan make:auth

Let us now create our first Dusk test:

php artisan dusk:make LoginTest

The above command will create a LoginTest class in our Browser directory.

class LoginTest extends DuskTestCase
     * A Dusk test example.
     * @return void
    public function test_I_can_login_successfully()
        $this->browse(function ($browser) {
                    ->type('email', 'viraj@virajkhatavkar.com')
                    ->type('password', 'secret')
                    ->assertSee('You are logged in!');

In the above test case, we check whether a user can successfully log into the system and see a home page with a welcome message.

Note: To make this test succeed, we need to have an actual user in the database. For this demonstration, we have already configured a user in the database with the above credentials.

Let us now execute our Dusk tests:

php artisan dusk

Let us now execute our Dusk tests with only single file LoginTest Class:

php artisan dusk tests/Browser/LoginTest.php

Creator of Shapecss, full stack developer and founder of MicroDreamIT. I wish to feel good if my blog help you developing your coding and career. I am also looking for project and consultancy. Please keep in touch with me in my twitter, facebook or other social network.


Leave a Reply

Your email address will not be published. Required fields are marked *