A great way of quickly testing your web applications inside October.
This plugin allows you to author functional tests using the playback tool built into Selenium’s portable framework without the need to learn a test scripting language. Write your tests in PHP, Python, Ruby and more.
How-to
System requirements
- Java 8 installed in default location of your platform (for example
/usr/bin/java
for Linux) - The driver of the browser you want to use for tests (for example ChromeDriver)
Note for Linux users
Installing Chromium from your package manager should install ChromeDriver for you
Note for Mac users
You probably will have to link newer version of Java to your default path as described here
Installation
- You can use three methods to install the plugin:
- from OctoberCMS Marketplace,
- clone the code from GitHub into
/plugins/initbiz/selenium2tests
directory or - install using Composer
composer require --dev initbiz/oc-selenium2tests-plugin
- Add
"laravel/dusk": "^2.0"
to yourrequire-dev
section incomposer.json
file - Go to
/plugins/initbiz/selenium2tests
- Copy
selenium.php.example
toselenium.php
and configure your environment
You can also create selenium.php
file in your root directory, which will be read when the one in plugin's directory does not exist
Testing OctoberCMS basics
It is a good practice not to use the same DB for testing and developing purposes.
In order to configure a different database for testing purposes create directory testing
in config
directory and copy database.php
to the newly-created directory. Then change the default connection as you wish.
After that, if you use APP_ENV=testing
in your .env
file, configuration from the testing
directory will be used.
Writing tests in Selenium 2
There are example tests in tests/example
directory that use Ui2TestCase
class.
Running tests
First of all, you have to run the Selenium 2 standalone server which is included in the package. In order to start Selenium 2 server go to <project_root>/plugins/initbiz/selenium2tests
and run java -jar selenium.jar
.
You are ready to run tests using PHPUnit from OctoberCMS's vendor/bin/phpunit
.
You can keep test files wherever you want, but .gitignore
of the plugin will exclude all files from /tests
except those in /tests/examples
.
Browser options (like headless mode)
If you want to for example run browser in headless mode, you can add that line to your selenium.php
file:
define('TEST_SELENIUM_BROWSER_OPTIONS', ['--headless']);
-
Art
Found the plugin useful on 18 May, 2020
Thanks for useful plugin! Still struggled through some challenges while configuring my testing environment.
- First, testing env was forcing to use sqlite driver and was throwing errors until I've installed sqlite driver.
- Some composer conflicts. meyfa/phpunit-assert-gd needs to be v2 and phpunit v8 in my case. Ended up with the following:
"require-dev": { "fzaninotto/faker": "~1.7", "phpunit/phpunit": "^8.0", "phpunit/phpunit-selenium": "~1.2", "meyfa/phpunit-assert-gd": "^2", "squizlabs/php_codesniffer": "3.*", "php-parallel-lint/php-parallel-lint": "^1.0", "laravel/dusk": "^2.0" },
- Few tests from default tests/ OctoberCMS dir was throwing errors. So I just commented them.
- Finally, I didn't copy database.php to config/testing. Instead, I created .env.testing in the project root, changing content of the .env to testing db credentials.
-
2.0.0 |
!!! Moved to Laravel Dusk API Sep 04, 2019 |
---|---|
1.0.15 |
Added support for record finder Mar 06, 2019 |
1.0.14 |
Added support for desired capabilities Mar 05, 2019 |
1.0.13 |
Better organized some October helpers, small doc fix and flash timeout Jan 28, 2019 |
1.0.12 |
Small fixes and features. Nov 07, 2018 |
1.0.11 |
Changed protected methods to public + updated Selenium standalone binary Nov 07, 2018 |
1.0.10 |
Added scrollToElement method Sep 13, 2018 |
1.0.9 |
Fixed notSee method Jul 06, 2018 |
1.0.8 |
Added select2 method Jul 03, 2018 |
1.0.7 |
Added timeout to waitForFlashMessage method Jul 03, 2018 |
1.0.6 |
Updated README file Apr 05, 2018 |
1.0.5 |
!!! Traits namespaced, updated Selenium standalone server Jan 17, 2018 |
1.0.4 |
October Selenium 2 helpers updated Sep 22, 2017 |
1.0.3 |
Added Selenium 2 Helpers methods Sep 21, 2017 |
1.0.2 |
Beta, some features might not work, but hey, you can contribute :) Sep 20, 2017 |
1.0.1 |
Initialize plugin. Sep 20, 2017 |