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.

Udemy Laravel Dusk Course

Laravel Dusk Beginner to Advanced

Video Course on Automation Testing, Web Scraping and Creating Bots using Dusk

> 60% OFF

Limited Time Offer

Learn More

2 comments On Generating a new Laravel Dusk Test

  • Hey Keerthana,
    Dusk should be able to find the test even though it’s in a directory. Make Sure your Test class ends with Test and also you have annotated your test with /** @test */ comment.

  • Hi,
    If I create a test under the directory structure Ex:php artisan dusk:make admin/LoginTest and try to run the test, I get ‘No tests executed’ error message. Do you have a workaround for this?

    Thanks

Leave a reply:

Your email address will not be published.

Site Footer