Behat Driver Update: Difference between revisions
Create drive update help docs |
David Mudrak (talk | contribs) m Text replacement - "<code>" to "<syntaxhighlight lang="php">" |
||
| Line 13: | Line 13: | ||
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: | 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: | ||
< | <syntaxhighlight lang="php"> | ||
$driver = $this->session->getDriver(); | $driver = $this->session->getDriver(); | ||
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) { | if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) { | ||
| Line 21: | Line 21: | ||
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 < | 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>. | ||
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. | ||
< | <syntaxhighlight lang="php"> | ||
$driver = $this->session->getDriver(); | $driver = $this->session->getDriver(); | ||
if ($driver instanceof \Moodle\BehatExtension\Driver\WebDriver) { | if ($driver instanceof \Moodle\BehatExtension\Driver\WebDriver) { | ||
| Line 36: | Line 36: | ||
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: | 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: | ||
< | <syntaxhighlight lang="php"> | ||
$session->getDriver()->getWebDriver()->getKeyboard()->sendKeys($keys); | $session->getDriver()->getWebDriver()->getKeyboard()->sendKeys($keys); | ||
</code> | </code> | ||
The Mink Driver implementation now in use (returned by < | 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. | ||
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. | ||
The replacement for the above example is: | The replacement for the above example is: | ||
< | <syntaxhighlight lang="php"> | ||
$this->session->getDriver()->getWebDriverSession()->keys([ | $this->session->getDriver()->getWebDriverSession()->keys([ | ||
'value' => $keys, | 'value' => $keys, | ||
Revision as of 13:05, 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:
<syntaxhighlight lang="php"> $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 <syntaxhighlight lang="php">\Moodle\BehatExtension\Driver\WebDriver.
Please note that the underliyng API for the driver may have also changed.
<syntaxhighlight lang="php"> $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:
<syntaxhighlight lang="php"> $session->getDriver()->getWebDriver()->getKeyboard()->sendKeys($keys);
The Mink Driver implementation now in use (returned by <syntaxhighlight lang="php">$this->session->getDriver()) has a different API to the original <syntaxhighlight lang="php">Mink/MinkSelenium2Driver and no longer has a <syntaxhighlight lang="php">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: <syntaxhighlight lang="php"> $this->session->getDriver()->getWebDriverSession()->keys([
'value' => $keys,
]);