Laravel

The power of Laravel Dusk, a browser automation testing tool

2019-03-15

Dusk is a powerful tool for writing browser tests in your Laravel Project

Laravel Dusk is a tool which provides an expressive, easy-to-use browser automation and testing API. Practically its just another PHP package for your project to fully functional browser tests.

By default, Dusk does not require you to install JDK or Selenium on your machine. Instead, Dusk uses a standalone ChromeDriver installation. However, you are free to utilize any other Selenium compatible driver you wish.

The Laravel Dusk installation is simple, after composer package installation just have to run:

php artisan dusk:install

The best thing is you can use all the power of Laravel framework for your browser tests as well. For instance, using Laravel Model Factories to seed data for your tests.

Using other browsers with Laravel Dusk

With laravel dusk you may start your own Selenium server and run your tests against any browser you wish. You just have to stop using ChromeDriver while preparing your instance in file tests/DuskTestCase.php

Environment handling in Laravel Dusk

We can create all together separate environment for dusk tests by just creating separate .env file for that dusk. To force Dusk to use its own environment file when running tests, create a .env.dusk.{environment} file in the root of your project. For example, if you will be initiating the dusk command from your local environment, you should create a .env.dusk.localfile.

Vuejs Assertions with Laravel Dusk

Laravel Dusk even allows you to make assertions on the state of Vue component data(Isn't is awesome :)). For example, imagine your application contains the following Vue component:

// HTML...
<profile dusk="profile-component"></profile>
// Component Definition...
Vue.component('profile', {
    template: '<div>{{ user.name }</div>',
    data: function () {
        return {
            user: {
              name: 'Taylor'
            }
        };
    }
});

You may assert on the state of the Vue component like so:

public function testVue()
{
    $this->browse(function (Browser $browser) {
        $browser->visit('/')
                ->assertVue('user.name', 'Taylor', '@profile-component');
    });
}

There are so many available assertions with proper documentation about them.

As a developer, I always see the problem for creating images/banners whenever I post some content online.

Even for simple designs I always needed to open figma or search online, so I thought of automating it.

I've build BannerPot to solve this problem, would you like to give it a try?

Ramesh from BannerPot

Ramesh Mhetre

Maker of BannerPot