Testing with Behat And Selenium

Start with https://docs.moodle.org/dev/Acceptance_testing#Installation. Follow the steps, but pay attention to running the next step “php composer.phar update –dev”. I had to do this before I could continue.

After completing all the steps, download http://selenium-release.storage.googleapis.com/2.48/selenium-server-standalone-2.48.2.jar and install the jar file through java (minimum java version 1.7).

ATTENTION: Moodle says not to use a version higher than 2.47.1. But in our tests, Selenium 2.47.1 didn't run in combination with more recent Firefox version (43.0.4).

Example: java -jar selenium-server-standalone-2.48.2.jar.

Run behat tests

I used three terminals to run the behat test. In the first start the server from your local public_html directory of the environment: php -S localhost:8000.

In the second start the selenium server: java -jar /path/to/selenium/selenium-server-standalone-2.48.2.jar

In the third start the behat test again from the local public_html directory. If you haven't run a behat test for this environment yet, first run: php admin/tool/behat/cli/init.php. This will create a new commmand that you can run, something like: vendor/bin/behat –config /path/to/your/behat/dataroot/directory/behat/behat.yml. Note: this will run all the behat tests of the environment.

If you want to run a specific behat test, specify the path after the previous command, so something like: vendor/bin/behat –config C:/PHP/projects/heidelberg/behat_data/behat/behat.yml C:/PHP/projects/heidelberg/heidelberg/blocks/last_visited_courses/tests/behat/configuring_last_visited_course s_block.feature.

Write own behat tests

You can create own scenarios and functions to run behat tests. Make sure to look at other scenarios for existing functionalities. Example: /auth/tests/behat/behat_auth.php.

In order to add own functions to run behat test, write in Frankenstyle format and see the documentation link below for an example.

When you have added own functions to behat, make sure to update the behat config before running the behat tests. You can update the behat config with the following command: php admin/tool/behat/cli/util.php –enable. Then you can run vendor/bin/behat.

More documentation about writing own behat tests on: https://docs.moodle.org/dev/Acceptance_testing#Writing_features

Personal Tools