mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-66979 behat: Core updates for W3C WebDriver
This commit updates core Behat features to make use of the php-webdriver/webdriver library instead of the legacy Instaclick library. Most of these changes relate to use of features of WebDriver which we are required to use directly rather than through the Mink Driver.
This commit is contained in:
parent
675ff118f2
commit
c5d25f9017
4 changed files with 24 additions and 24 deletions
|
@ -23,11 +23,12 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use Behat\Mink\Element\Element;
|
||||
use Behat\Mink\Exception\DriverException;
|
||||
use Behat\Mink\Exception\ExpectationException;
|
||||
use Behat\Mink\Exception\ElementNotFoundException;
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use Behat\Mink\Element\Element;
|
||||
use Behat\Mink\Exception\NoSuchWindowException;
|
||||
use Behat\Mink\Session;
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
@ -35,9 +36,8 @@ use Behat\Mink\Session;
|
|||
require_once(__DIR__ . '/component_named_replacement.php');
|
||||
require_once(__DIR__ . '/component_named_selector.php');
|
||||
|
||||
// Alias the WebDriver\Key class to behat_keys to make future transition to a different WebDriver implementation
|
||||
// easier.
|
||||
class_alias('WebDriver\\Key', 'behat_keys');
|
||||
// Alias the Facebook\WebDriver\WebDriverKeys class to behat_keys for better b/c with the older Instaclick driver.
|
||||
class_alias('Facebook\WebDriver\WebDriverKeys', 'behat_keys');
|
||||
|
||||
/**
|
||||
* A trait containing functionality used by the behat base context, and form fields.
|
||||
|
@ -253,9 +253,7 @@ trait behat_session_trait {
|
|||
* @param string[] $keys
|
||||
*/
|
||||
public static function type_keys(Session $session, array $keys): void {
|
||||
$session->getDriver()->getWebDriverSession()->keys([
|
||||
'value' => $keys,
|
||||
]);
|
||||
$session->getDriver()->getWebDriver()->getKeyboard()->sendKeys($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -833,7 +831,7 @@ EOF;
|
|||
return M.util.pending_js.join(":");
|
||||
})()'));
|
||||
$pending = self::evaluate_script_in_session($session, $jscode);
|
||||
} catch (NoSuchWindow $nsw) {
|
||||
} catch (NoSuchWindowException $nsw) {
|
||||
// We catch an exception here, in case we just closed the window we were interacting with.
|
||||
// No javascript is running if there is no window right?
|
||||
$pending = '';
|
||||
|
@ -973,7 +971,7 @@ EOF;
|
|||
}
|
||||
}
|
||||
|
||||
} catch (NoSuchWindow $e) {
|
||||
} catch (NoSuchWindowException $e) {
|
||||
// If we were interacting with a popup window it will not exists after closing it.
|
||||
} catch (DriverException $e) {
|
||||
// Same reason as above.
|
||||
|
|
|
@ -218,12 +218,15 @@ class behat_form_field implements behat_session_interface {
|
|||
* @return int
|
||||
*/
|
||||
protected function get_internal_field_id() {
|
||||
|
||||
if (!$this->running_javascript()) {
|
||||
throw new coding_exception('You can only get an internal ID using the selenium driver.');
|
||||
}
|
||||
|
||||
return $this->session->getDriver()->getWebDriverSession()->element('xpath', $this->field->getXPath())->getID();
|
||||
return $this->getSession()
|
||||
->getDriver()
|
||||
->getWebDriver()
|
||||
->findElement(WebDriverBy::xpath($node->getXpath()))
|
||||
->getID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -271,7 +271,7 @@ class behat_general extends behat_base {
|
|||
* @Given /^I accept the currently displayed dialog$/
|
||||
*/
|
||||
public function accept_currently_displayed_alert_dialog() {
|
||||
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
|
||||
$this->getSession()->getDriver()->getWebDriver()->switchTo()->alert()->accept();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -279,7 +279,7 @@ class behat_general extends behat_base {
|
|||
* @Given /^I dismiss the currently displayed dialog$/
|
||||
*/
|
||||
public function dismiss_currently_displayed_alert_dialog() {
|
||||
$this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert();
|
||||
$this->getSession()->getDriver()->getWebDriver()->switchTo()->alert()->dismiss();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -418,7 +418,8 @@ class behat_general extends behat_base {
|
|||
*/
|
||||
public function i_click_on_confirming_the_dialogue($element, $selectortype) {
|
||||
$this->i_click_on($element, $selectortype);
|
||||
$this->accept_currently_displayed_alert_dialog();
|
||||
$this->execute('behat_general::accept_currently_displayed_alert_dialog', []);
|
||||
$this->wait_until_the_page_is_ready();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -431,7 +432,8 @@ class behat_general extends behat_base {
|
|||
*/
|
||||
public function i_click_on_dismissing_the_dialogue($element, $selectortype) {
|
||||
$this->i_click_on($element, $selectortype);
|
||||
$this->dismiss_currently_displayed_alert_dialog();
|
||||
$this->execute('behat_general::dismiss_currently_displayed_alert_dialog', []);
|
||||
$this->wait_until_the_page_is_ready();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1802,16 +1804,16 @@ EOF;
|
|||
$modifier = trim($key);
|
||||
switch (strtoupper($key)) {
|
||||
case 'UP':
|
||||
$keys[] = behat_keys::UP_ARROW;
|
||||
$keys[] = behat_keys::ARROW_UP;
|
||||
break;
|
||||
case 'DOWN':
|
||||
$keys[] = behat_keys::DOWN_ARROW;
|
||||
$keys[] = behat_keys::ARROW_DOWN;
|
||||
break;
|
||||
case 'LEFT':
|
||||
$keys[] = behat_keys::LEFT_ARROW;
|
||||
$keys[] = behat_keys::ARROW_LEFT;
|
||||
break;
|
||||
case 'RIGHT':
|
||||
$keys[] = behat_keys::RIGHT_ARROW;
|
||||
$keys[] = behat_keys::ARROW_RIGHT;
|
||||
break;
|
||||
case 'HOME':
|
||||
$keys[] = behat_keys::HOME;
|
||||
|
@ -1852,9 +1854,6 @@ EOF;
|
|||
throw new \coding_exception("Unknown key '$key'}");
|
||||
}
|
||||
|
||||
// Always send the NULL key as the last key.
|
||||
$keys[] = behat_keys::NULL_KEY;
|
||||
|
||||
behat_base::type_keys($this->getSession(), $keys);
|
||||
}
|
||||
|
||||
|
|
|
@ -644,7 +644,7 @@ EOF;
|
|||
// the following scenarios. Some browsers already closes the alert, so
|
||||
// wrapping in a try & catch.
|
||||
try {
|
||||
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
|
||||
$this->getSession()->getDriver()->getWebDriver()->switchTo()->alert()->accept();
|
||||
} catch (Exception $e) {
|
||||
// Catching the generic one as we never know how drivers reacts here.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue