Automating Test Using Laravel Dusk
Test automation is an important part of software development and as such the sooner you start at it the better. Laravel offers a complete set of tools you can use to make software testing a project easy. One of this tools is Dusk an easy-to-use browser automation and testing API.
Installation
Installing Dusk is a simple task:
- Add the Composer dependency to the project
composer require --dev laravel/dusk
- Register the Service Provider in the project
Important: For security reasons, do not register Dusk Service Provider in the Production Environment
Register Dusk Service Provider in the project:
- Go to app\Provider\AppServiceProvider.php
- Add the code:
use Laravel\Dusk\DuskServiceProvider;
In the Function register:
if ($this->app->environment(['local', 'testing'])) {
$this->app->register(DuskServiceProvider::class);
}
- Run the Artisan command to setup Dusk in the project tree
php artisan dusk:install
Dusk Test Automation
According to the documentation, Dusk uses Google Chrome and a standalone ChromeDriver installation to run your browser tests by default. To keep it as simple as possible, in this example I will not alter the default behavior and will keep using Chrome as the test browser. But it is possible to alter Dusk’s behavior to integrate with other tools such as Facebook’s PHP Web Driver with Selenium.
Create a NEW Test Case
php artisan dusk:make <TestCaseName>
Example:
php artisan dusk:make RegisterTest
This creates a file RegisterTest.php inside the tests\Browser folder.
Run the tests:
php artisan dusk
References
Larvel Dusk Date Accessed: 2018-09-04
comments powered by Disqus