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

Livewire Component Library
<?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

Host Laravel Application on DigitalOcean

Use coupon 5balloons on this Cloudways Affiliate URL to get special discount.

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

Site Footer