Behat Driver Update

Jump to: navigation, search

This documentation relates to MDL-66979 and changes to the WebDriver implementation that we use within Moodle's Behat testing infrastructure. It describes common scenarios which you may encounter as a result of these changes, and how to address them.

These changes affect the following branches, from Friday 29th January 2021 onwards:

  • master (Moodle 4.0 development)
  • MOODLE_311_STABLE (Moodle 3.11 development)
  • MOODLE_310_STABLE (Moodle 3.10 release branch)
  • MOODLE_39_STABLE (Moodle 3.9 release branch)

Note: Changes to Behat, and Behat infrastructure are typically applied to all supported branches and are not master-only. Ordinarily this includes security release, but minimum PHP version support prevents that on this occasion.

Checking the type of Mink Driver

There are a small number of occasions where you may felt that you needed to check the type of driver currently in use. To do so, you may have used code such as the following:

$driver = $this->session->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
    // ...
}


As part of this change, we have changed the driver that we use from Mink\MinkSelenium2Driver to OAndreyev\MinkPhpWebDriver. The way in which Moodle extends the driver has also changed, and it is now located at
\Moodle\BehatExtension\Driver\WebDriver
.

Please note that the underliyng API for the driver may have also changed.

$driver = $this->session->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\WebDriver) {
    // ...
}


Accessing the WebDriver directly

The general recommendation is that you should not need to access the WebDriver implementation directly. In the unusual situation that you do need to access WebDriver, then you may have used code such as the following:

$session->getDriver()->getWebDriver()->getKeyboard()->sendKeys($keys);
The Mink Driver implementation now in use (returned by
$this->session->getDriver()
) has a different API to the original
Mink/MinkSelenium2Driver
and no longer has a
getWebDriver()
function.

In addition the WebDriver implementation has a different API, more in-keeping with the Java WebDriver API. You may need to update your calls within the WebDriver implementation.

The replacement for the above example is:

$this->session->getDriver()->getWebDriverSession()->keys([
    'value' => $keys,
]);