Laravel Dusk provides simple end-to-end testing and browser automation.

0.1.16 2019-03-21 15:11 UTC

This package is auto-updated.

Last update: 2020-10-21 18:54:56 UTC



Build Status Total Downloads Latest Stable Version License

Laravel 5.1

Build Status Total Downloads Latest Stable Version License


Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK or Selenium on your machine. Instead, Dusk uses a standalone Chromedriver. However, you are free to utilize any other Selenium driver you wish.

Official Documentation

Documentation for Dusk can be found on the Laravel website.


To get the last version of Laravel Dusk for 5.1, simply require the project using Composer:

composer require --dev josrom/laravel-dusk-5.1

Instead, you may of course manually update your require block and run composer update if you so choose:

    "require-dev": {
        "josrom/laravel-dusk-5.1": "0.1.*"

Add the service provider app/Providers/AppServiceProvider.php file:

if ($this->app->environment('local')) {

After installing the Dusk package, run the dusk:install Artisan command:

php artisan dusk:install

A Browser directory will be created within your tests directory and will contain an example test. Next, set the APP_URL environment variable in your .env file. This value should match the URL you use to access your application in a browser.

To run your tests, use the dusk Artisan command. The dusk command accepts any argument that is also accepted by the phpunit command:

php artisan dusk


By default dusk use the port 9515 and have a timeout of 20 seconds.

If you need change the configuration the dusk port and/or timeout, it is needed to publish the config file:

php artisan vendor:publish --provider="Laravel\Dusk\DuskServiceProvider" --tag="config"

To make the changes by environment variables*, add the fields in the dusk env file.

Extra methods

Method Definition
switchFrame (type of selector, value of selector)
select2 (selector, value(s), wait in seconds)
selectBySelector (selector css, value of selector)
assertFragmentIs (value of fragment)
assertQueryIs (value of query)
scrollTo (selector jQuery)
wysiwyg (type of wysiwyg: tinymce, ID of wysiwyg, value)



Example of payment with paypal using the switchFrame method:

    ->assertSee('Some Event')
    ->clickLink('Register Now')
    ->assertSee('Some Event')
    ->press('Submit Application')
    ->assertSee('Your application has been submitted.')
    ->waitFor('#injectedUnifiedLogin', 30)
    ->type('#email', env('PAYPAL_TEST_BUYER_USERNAME'))
    ->type('#password', env('PAYPAL_TEST_BUYER_PASSWORD'))
    ->waitFor('#confirmButtonTop', 30)
    ->waitForText('You paid', 30)
    ->waitForText('Events Registration', 30)
    ->pause(10000) // waiting for IPN callback from paypal
    ->assertSee('Payment verified')


Example of select2 uses:

  • For default select2. If value not passed, it be selected automatically:
  • Another way, if need concrete value:
$browse->select2('@selector', 'you_text_value');
  • For multiple mode usage like this:
$browse->select2('@selector', ['foo', 'bar'], 5);
  • Css-selector for the select html tag should be ends with + select2 name:
<select class="form-control select2-users" name="user_id">
$browse->select2('.select2-users + .select2', 'you_text_value');


Example of selectBySelector uses:

$browse->selectBySelector('', 'value');


Example of assertFragmentIs uses:



Example of assertQueryIs uses:



Example of scrollTo uses:



Example of wysiwyg uses:

        ->wysiwyg('tinymce', 'form-id', '<h2>value</h2>');


Laravel Dusk is open-sourced software licensed under the MIT license