Laravel - Browser Tests - Authentication

Often, you will be testing pages that require authentication. You can use Dusk's loginAs method in order to avoid interacting with your application's login screen during every test. The loginAs method accepts a primary key associated with your authenticatable model or an authenticatable model instance:

    
    use App\Models\User;
    
    $this->browse(function ($browser) {
        $browser->loginAs(User::find(1))
              ->visit('/home');
    });
	
After using the loginAs method, the user session will be maintained for all tests within the file.