I need to run one of my Laravel Dusk tests from an artisan command so that it processes daily. I've tried $this->call('dusk'); in my command but that runs all of dusk's tests and doesn't allow me to add a group or a filter. I need to run just 1 test. How can I add a filter?
$this->call('dusk', [ '--group' => 'communication_tests' ]);
or
$this->call('dusk', [ '--filter' => 'tests\Browser\myTestFile::myTestMethod' ]);
doesn't work and it ignores the options passed in. Any ideas on how to accomplish this?
1st create your working Laravel Dusk Test. Test it out with php artisan dusk and make sure it's working.
2nd create your own command in the app\Commands folder called DuskCommand to overwrite laravels native DuskCommand and have it's signature be 'dusk'. Have it extend Laravel\Dusk\Console\DuskCommand and write into its handle method the code below (see https://github.com/laravel/dusk/issues/371 for other version of this code). I edited mine to remove the
$this->option('without-tty') ? 3 : 2ternary statement so it just reads2for mine as that option didn't exist or wasn't needed for my version of laravel.3rd add your new class to the Kernel so that when you call php artisan dusk the class is recognized.
4th create your new command to programmatically run your dusk test using the final line added by @taytus.
5th add that new class to the Kernel also.
Here's my file run down below...
My laravel dusk test (tests\Browser\CommunicationsTest.php) (STEP 1)
My Overwritting dusk command (app\Console\Commands\DuskCommand.php) (STEP 2)
Now add that new command to the Kernel so it will register when you call it and overwrite the functionality of the native/vendor DuskCommand. (STEP 3)
Now create your command that will call dusk programmatically - here's mine (STEP 4)
and register it in the Kernel (STEP 5)...
Now run
php artisan duskand it should hit the extending DuskCommand and work fine. Then call your new php artisan command that replaces my TestCommunications.php file and it should run dusk perfectly... assuming your test works of course. Let me know if you have any question or if I left anything out.Remember Dusk only works in a local environment ... this is not something you want/should/natively can implement on a production environment