Laravel Dusk has been most awaited futures that added in laravel 5.4 as its provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require we to install JDK or Selenium on our machine. Instead, Dusk uses a standalone ChromeDriver installation. However, wer are free to utilize any other Selenium compatible driver we wish.
Since Dusk operates using a real browser, we are able to easily test and interact with our applications that heavily use JavaScript:
A simaple example like below
public function testPcds()
{
$user = factory(User::class)->create([
'email' => 'rom@pcds.co.in',
]);
$this->browse(function ($browser) use ($user) {
$browser->loginAs($user)
->visit('/home')
->press('Create Playlist')
->whenAvailable('.playlist-modal', function ($modal) {
$modal->type('name', 'My Playlist')
->press('Create');
});
$browser->waitForText('Playlist Created');
});
}