How to create multiple browsers using laravel dusk?

Run below srtisan command to generate the test class file

php artisan dusk:make MultipleBrowserTest
browse(function ($first, $second) {
                $first->loginAs(User::find(1))
                    ->visit('/home')
                    ->waitForText('Message');
         $second->loginAs(User::find(2))                                 
              ->visit('/home')                 
              ->waitForText('Message')      
             ->type('message', 'Hey Taylor')                                
             ->press('Send');                       
     
     $first->waitForText('Hey Taylor')                              
            ->assertSee('Jeffrey Way'); 
     })
    }   
 }

Now you can run this test with below artisan command

php artisan dusk

If you get error – Error: Call to undefined function Tests\Browser\factory()
the run below command to include the legacy factory

composer require laravel/legacy-factories

Leave a Comment

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