This repository contains a Docker Compose setup for running a Selenium Grid with Chrome and Firefox browsers for testing Moodle applications.
All the necessary configurations are included to get you started quickly without any additional setup such as installing browser drivers or configuring the Selenium Grid manually.
-
Install Docker and Docker Compose on your machine.
-
Clone this repository to your local machine.
-
Navigate to the cloned repository directory.
-
Copy
.env.exampleto.envand adjust for your architecture:cp .env.example .env
- AMD64: no change needed —
selenium/node-chrome:latestis the default. - arm64 (Apple Silicon / Linux ARM): set
CHROME_IMAGE=selenium/node-chromium:latestin.env.
- AMD64: no change needed —
-
Start the grid:
docker compose pull docker compose up -d
-
Set up the test host e.g. 'behat.test' in your
/etc/hostsfile:127.0.0.1 localhost behat.test
-
Open your Moodle
config.phpin your preferred editor. -
Add the following lines to the
config.phpfile:$CFG->behat_wwwroot = 'http://behat.test'; $CFG->behat_profiles = [ 'chrome' => [ 'browser' => 'chrome', 'capabilities' => [ 'extra_capabilities' => [ 'goog:chromeOptions' => [ 'args' => [ 'no-sandbox', 'no-gpu', 'disable-save-password-bubble', ], 'prefs' => [ // Disable the Credential service. 'credentials_enable_service' => false, // Disable the Password manager. 'profile.password_manager_enabled' => false, 'profile.password_manager_leak_detection' => false, ], ], ], ], 'wd_host' => 'http://localhost:4444/wd/hub', ], 'firefox' => [ 'browser' => 'firefox', 'capabilities' => [ 'marionette' => true, ], 'wd_host' => 'http://localhost:4444/wd/hub', ], ];
Or you can use Andrew's Moodle Behat Browser configuration utility to generate the browser configuration for you.
-
Run behat, specifying one of the defined browsers as a profile, for example:
vendor/bin/behat --profile=chrome --config=/moodledata_behat/behatrun/behat/behat.yml --tags=@core_ai
-
The supported profiles are:
chromefor latest Google Chrome (Chromium on arm64)firefoxfor latest Mozilla Firefox
- Download a VNC viewer application (e.g., RealVNC, TightVNC, etc.) on your local machine.
- With the containers running, enter the following information in your VNC viewer:
- VNC Server:
localhost:5900for Chrome,localhost:5901for Firefox. - Password:
secret
- VNC Server:
- You should be able to see an empty Desktop. When you run any Javascript requiring Behat tests (e.g. those tagged @javascript) a browser will popup and you will see the tests execute.
Video recording is disabled by default. To enable it, uncomment COMPOSE_PROFILES=video in your .env file. This spins up chrome_video, firefox_video, and file_browser alongside the grid.
When enabled:
- Test runs are recorded for both Chrome and Firefox and saved to the
./videosdirectory. - Only failed test videos are retained (
SE_RETAIN_ON_FAILURE=true). - File names are set automatically based on the session (
SE_VIDEO_FILE_NAME=auto). - A file browser is available at http://localhost:8081 to view and manage recordings. No login is required.