Skip to content
Mark Metcalfe edited this page Oct 4, 2021 · 35 revisions

Running Behat with debugging

You can connect to the selenium container via VNC to view what is being executed in the browser, which is very helpful for when writing/fixing tests.

To do this, you need to set your behat host to selenium-chrome-debug in your config.php. If you are using the config.php that comes with docker-dev, simply find $DOCKER_DEV->behat_parallel and set it to false.

Now start the selenium debug container:

tup selenium-chrome-debug

You will then need to re-initialise behat:

cd sitefolder # must run the command from the root of your Totara repo
tzsh php-7.3 # or other php containers, as mentioned above
installbehat

Now you can run it:

behat --name="Name of the scenario"

In a VNC client, connect using the following credentials to view the scenario running:

Host Port Password
localhost 5901 secret

If you can't see the scenario executing, it may be because the scenario is missing the @javascript tag. If the tag isn't specified for the scenario it will run it in headless mode, meaning selenium won't be used.

Running Behat in parallel

If you just want to run a suite of behat tests, then it is much faster (and recommended) to run behat in parallel mode (i.e. across multiple threads simultaneously)

To get started, you'll need to start the selenium containers. For the following examples, we are going to run behat across 4 threads. You can adjust this number based on your computers performance.

tup selenium-hub
tscale selenium-chrome 4 # Creates 4 selenium containers for running across 4 threads

Log into one of the PHP containers:

cd sitefolder # must run the command from the root of your Totara repo
tzsh php-7.3 # or other php containers, as mentioned above

Initiate the behat tests:

# See shell/totara-aliases.sh for what these aliases do
installbehat --parallel=4 # Initiates for 4 threads
# If you are wanting to run a specific tag, then you can optimise behat for it
installbehat --parallel=4 --optimise-runs=@totara

Run behat with:

# See shell/totara-aliases.sh for what these aliases do
# Run all scenarios (takes several hours)
behat
# Run a specific tag
behat --tags=@totara
# Run a specific scenario
behat --name="Name of the scenario"
# Run a specific feature file
behat path/to/feature/file

To see the status of the selenium containers while they are executing, go to http://localhost:4444/grid/console to view the web console.

Clone this wiki locally