Browser testing for October CMS, powered by Laravel Dusk.
To install with Composer, run from your project root
composer require rainlab/dusk-pluginIf using the latest version of Chrome, install the latest version of ChromeDriver for your OS.
php artisan dusk:chrome-driverOtherwise, check the version of the Chrome browser you have installed, and install a given version of ChromeDriver for your OS.
php artisan dusk:chrome-driver 86To make your first test, create a new class inside the tests/browser folder of your plugin. The following will authenticate to the backend panel and sign out again.
// File: plugins/acme/blog/tests/browser/AuthenticationTest.php
//
class AuthenticationTest extends BrowserTestCase
{
public function testAuthentication()
{
$this->browse(function($browser) {
$browser
->visit('/admin')
->waitForLocation('/admin/backend/auth/signin')
->assertTitleContains('Administration Area |')
->type('login', env('DUSK_ADMIN_USER', 'admin'))
->type('password', env('DUSK_ADMIN_PASS', 'admin'))
->check('remember')
->press('Login');
$browser
->waitForLocation('/admin/dashboard')
->assertTitleContains('Dashboard |')
->click('#layout-mainmenu .mainmenu-account > a')
->clickLink('Sign Out');
$browser
->waitForLocation('/admin/backend/auth/signin')
->assertTitleContains('Administration Area |');
});
}
}The .env.dusk environment file can be used for Dusk specific configuration. It is advisable to include the application URL to test in this file, along with the administrator credentials used by the example test above.
APP_URL=http://mylocalsite.dev/
DUSK_ADMIN_USER=admin
DUSK_ADMIN_PASS=adminUse the test:dusk artisan command to run the dusk tests for a plugin code (first argument).
php artisan test:dusk <PLUGIN CODE>The following runs tests for the Acme.Blog plugin.
php artisan test:dusk acme.blogUse the --browse to enable interactive mode.
php artisan test:dusk acme.blog --browseUse the --filter option to run a single test where the value is the test class name.
php artisan test:dusk acme.blog --filter=AuthenticationTest
Follow these instructions to get a test up and running.
-
Install the latest version of Chrome browser
-
Install a fresh copy of October CMS
-
Install this plugin
composer require rainlab/dusk-plugin -
Install latest chrome driver
php artisan dusk:chrome-driver -
Create a plugin to hold the tests
php artisan create:plugin Acme.Blog -
Save the
AuthenticationTestclass from Defining Tests asplugins/acme/blog/tests/browser/AuthenticationTest.php -
Create a file
.env.duskand includeAPP_URL=http://yourlocaldev.tldinside, along withDUSK_ADMIN_USERandDUSK_ADMIN_PASSif your administrator is not admin/admin -
Run tests
php artisan test:dusk acme.blog --browse
This plugin is an official extension of the October CMS platform and is free to use if you have a platform license. See EULA license for more details.