Skip to content
Mark Metcalfe edited this page Nov 3, 2021 · 26 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.

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

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

Run behat with:

# Run a specific scenario
behat --name="Name of the scenario"

# Run a specific feature file (the path must be relative to the site root or the full path)
behat path/to/feature/file

# Run a specific tag
behat --tags=@totara

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)

If you are using the example config.php that comes with docker-dev, simply find $DOCKER_DEV->behat_parallel and set it to true. If you are not using the example config.php, then you'll need to set your behat host to selenium-hub in your config.php.

You'll then 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

# Initiate behat for the number of threads defined in $DOCKER_DEV->behat_parallel_count in config.php
installbehat

# If you are wanting to run a specific tag, then you can optimise behat for it
installbehat --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 (the path must be relative to the site root or the full path)
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