Moodle Behat: Accessing host chromedriver from docker

Guy Thomas
1 min readMar 15, 2023

From time to time, you may want Behat tests on your docker container to connect to chromedriver on your host so that you can easily debug a failing Behat test.

To do this, it is important that chromedriver is started as follows:

chromedriver --whitelisted-ips= --allowed-origins=host.docker.internal

Your Moodle Behat config will then need to reference your host. This is done by setting ‘wd_host’ to ‘host.docker.internal:9515’

$CFG->behat_profiles = [
'default' => [
'browser' => 'chrome',
'tags' => '@javascript',
'wd_host' => 'host.docker.internal:9515'
],
'headless' => [
'browser' => 'chrome',
'wd_host' => 'host.docker.internal:9515',
'tags' => '@javascript',
'capabilities' => [
'chrome' => [
'switches' => [
'--no-sandbox',
'--headless',
'--disable-gpu'
]
],
'extra_capabilities' => [
'chromeOptions' => [
'args' => [
'headless',
'no-gpu'
]
]
]
]
]
];

Running Behat on your docker container now will allow you to see the tests running on your host.

If you want Behat to use chromedriver on your host but run in the background, add the headless switch as per the following example.

vendor/bin/behat --config /yourmoodlepath/behat/behatrun/behat/behat.yml --profile=headless

--

--