Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Behat Driver Update: Difference between revisions

From MoodleDocs
m (Text replacement - "<code>" to "<syntaxhighlight lang="php">")
m (Text replacement - "</code>" to "</syntaxhighlight>")
Line 18: Line 18:
     // ...
     // ...
}
}
</code>
</syntaxhighlight>




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 <syntaxhighlight lang="php">\Moodle\BehatExtension\Driver\WebDriver</code>.
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 <syntaxhighlight lang="php">\Moodle\BehatExtension\Driver\WebDriver</syntaxhighlight>.


Please note that the underliyng API for the driver may have also changed.
Please note that the underliyng API for the driver may have also changed.
Line 30: Line 30:
     // ...
     // ...
}
}
</code>
</syntaxhighlight>




Line 38: Line 38:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
$session->getDriver()->getWebDriver()->getKeyboard()->sendKeys($keys);
$session->getDriver()->getWebDriver()->getKeyboard()->sendKeys($keys);
</code>
</syntaxhighlight>


The Mink Driver implementation now in use (returned by <syntaxhighlight lang="php">$this->session->getDriver()</code>) has a different API to the original <syntaxhighlight lang="php">Mink/MinkSelenium2Driver</code> and no longer has a <syntaxhighlight lang="php">getWebDriver()</code> function.
The Mink Driver implementation now in use (returned by <syntaxhighlight lang="php">$this->session->getDriver()</syntaxhighlight>) has a different API to the original <syntaxhighlight lang="php">Mink/MinkSelenium2Driver</syntaxhighlight> and no longer has a <syntaxhighlight lang="php">getWebDriver()</syntaxhighlight> 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.
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.
Line 49: Line 49:
     'value' => $keys,
     'value' => $keys,
]);
]);
</code>
</syntaxhighlight>


[[Category:Behat]]
[[Category:Behat]]

Revision as of 13:07, 14 July 2021

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,
]);