Totara Learn Open Discussions

Totara + Behat tests

 
Davo Smith
Totara + Behat tests
by Davo Smith - Friday, 25 August 2023, 3:55 AM
Group Partners

I'm wondering if anyone else has had any recent problems running Behat tests against Totara.

I've been running tests fine for years, using selenium (3.141.59) and chromium and tests are still working perfectly for Moodle, but recently something has stopped all tests from working in Totara.

When I run the tests, a browser window is opened, but doesn't seem to connect to the Totara Behat test running code.

I've traced through the code and I've attached the parameters that are sent to the selenium server and the response generated from that server.

Moodle (4.2) seems to be using more recent versions of various Behat-related libraries, which seems to be able to open up a new browser session without any problems.

I've attached the parameters that Moodle sends to create the session.

I've even tried manually editing the 'session()' function in webDriver.php to hard-code in the parameters that Moodle is using. This actually seems to work for a few moments, but then gets stuck with an error:
"unknown command: Cannot call non W3C standard command while in W3C mode".

My guess is that a recent Chromium update has stopped it from working in non-W3C mode, but Totara is still trying to call it in that mode (whereas Moodle has been updated to work with W3C mode).

Does anyone have any insights that might help, as being unable to run Behat tests is causing me major development headaches?

Davo Smith
Re: Totara + Behat tests
by Davo Smith - Friday, 25 August 2023, 4:06 AM
Group Partners

After a bit more digging, if I edit the generated behat.yml file and change all references to 'w3c' from 'w3c: false' to 'w3c: true', then it all seems to start working properly …

This is still a workaround, rather than a fix, but it looks like it'll get me back up and running for today.

Bryn Whyman
Re: Totara + Behat tests
by Bryn Whyman - Sunday, 27 August 2023, 9:57 PM
Group Totara

Hey Davo

You are right this is as a result of a recent Chromium update.

The JSON wire protocol (as used when the w3c variable is set to false) is no longer working. This was accepted by Chrome driver, which is no longer produced by Google (with the last version being 114, which supported up to Chrome 115). Selenium 4.8 was also the last version of Selenium that allowed the JSON wire protocol.

This is on our radar at Totara, the Behat test suite needs some work.

Another workaround is to use a Chrome docker image (with the highest version of 106) from https://hub.docker.com/u/selenium

Further configuration of Behat can be achieved by placing a file called `behat_local.yml` in the `test\behat\` directory and overriding the options that you've seen in the behat.yml file. This would allow you to override w3c property in a safer way (and a number of other properties as well).