Laravel dusk testing cheat sheet

 //test a URI 

  //test a route

 //browser back


 $browser->forward(); //browser forward

 $browser->refresh(); //refresh page

 $browser->resize(1920, 1080); //resize browser window

 $browser->maximize(); //maximise browser window

 $browser->fitContent(); //maximise to fit the content of the browser

 $browser->disableFitOnFailure(); // disable above operation on failure

 $browser->move($x = 100, $y = 100); // move browser window to different positions

 //test page which require authentication, after loginAs method user session will be maintained

 use App\Models\User;
 $this->browse(function ($browser)) {


 $browser->screenshot('filename'); //this will store the screenshot test/browser/console directory

 //prefix @ to use dusk selector

 //set value for a input field using value method
 $browser->value('selector', 'value');

 //set value for a input field using inputValue method

 //display text for an element for the give selector

 //get attributes for a matching the field
 $browser->attribute('selector', 'value');

 //type text into input field
 $browser->type('email','[email protected]');

 //use append method to add more content without clearing previous data
         ->append('tags' 'world');

 //clear value of an input field

// Dusk will type input field slowly (100ms default)
 $browser->typeslowly('phone', '123 456 789');

 $browser->type('tags', 'foo')
         ->appendSlowly('tags', ', bar, baz');

 // select a value for a dropdown field

 //select a random option for dropdown with one argument

 //tick a checkbox, terms is the name of checkbox field

 //untick a checkbox

 //select a radio button
 $browser->radio('size', 'large');

 //attach a file
 $browser->attach('photo', DIR.'/test.png');

 //press a button

/wait for 5sec and then press the button

 //wait for 1sec and then press the button

 $browser->pressAndWaitFor('Save', 1);
 //click a link which displays text "click here"
 $browser->clickLink("click here");

 // check if you can see the link text
 $browser->seeLink("click here");