Generating a new Laravel Dusk Test

In this tutorial we will go over on how you can generate a new Laravel Dusk test for the browser automation testing. Before diving in make sure you have Installed the Laravel Dusk package.

To generate a new dusk test use the artisan command dusk:make. The test generated will be placed in tests/Browser directory

php artisan dusk:make newDuskTest

If you want to put your new test in a new directory under Browser, this is useful when you are organizing tests as per different sections of your web application.

php artisan dusk:make admin/LoginTest

This test will be placed under admin directory inside tests/Browser

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class newDuskTest extends DuskTestCase
{
    /**
     * A Dusk test example.
     *
     * @return void
     */
    public function testExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->assertSee('Laravel');
        });
    }
}

The new dusk test extends the DuskTestCase, and contains an example test method named testExample

You can remove the testExample class and start writing you new dusk method.

Next up you can learn all about Running your dusk tests.

Web Stuff Enthusiast.

Leave a reply:

Your email address will not be published.

Site Footer