Home

2 minute read

Laravel TestTools for your Dusk Tests

Tony Lea

Laravel TestTools for your Dusk Tests

Laravel TestTools is an awesome and easy to use Chrome Extension. You can install this extension on chrome and then press record and start creating dusk tests as you click around in your application.

In this tutorial you will see just how easy it is to use.

Download the chrome extension

First, you'll want to head on over to the Chrome store and download the extension.

Create a Laravel App

Let's create a new laravel app by running our laravel new command:

laravel new testtools

This will create a new application inside of our testtools folder. Next we will want to add the default Laravel Authentication, cd into the testtools folder and run the auth scaffold command:

php artisan make:auth

Next, make sure to create a new database and add your database credentials to your .env file. And now, we are ready to run our migrations:

php artisan migrate

We have our new app in front of us:

We can now, login and register with our application.

Create our Dusk Test

Next, after downloading and installing the Laravel TestTools chrome extension, you will want to open up Developer Tools and you will see a new tab called Laravel TestTools

Next, to create a Dusk test we will want to click on the Settings tab.

And then click the checkbox that says Create Laravel Dusk Tests.

Before we move on, go ahead and create an account by registering a new user in your application.

Now, we are ready to create a test. Click on the Record button in the Laravel TestTools tab.

And then click on login and log in with your new user. After you have successfully logged in you can press Pause in the TestTools tab, and low and behold, you have a dusk test in front of you which will look similar to the following:


use Tests\DuskTestCase;
use Laravel\Dusk\Browser;

class Test extends DuskTestCase
{

    /**
     * My test implementation
     */
    public function testMiddlewareIsFantastic()
    {

        $this->browse(function (Browser $browser) {
            $browser->visit('/');
            $browser->clickLink('Login');
            $browser->visit('/login');
            $browser->type('email', '[email protected]');
            $browser->type('password', 'password123');
            $browser->press('Login');
            $browser->assertPathIs('/home');
        });

    }
}

You can now add this to your Dusk test folder and it will be added to your test suite!

Since it's super easy to create Dusk tests, there should be no reason you're not adding tests to all your applications.

Be sure to head on over to https://chrome.google.com/webstore/detail/laravel-testtools/ddieaepnbjhgcbddafciempnibnfnakl?hl=en and install this awesome chrome extension :)