MDL-39348 behat: Compatibility with Safari and IE
Also changing from SeleniumDriver checking to GoutteDriver as is less probably to change goutte than to change selenium.
This commit is contained in:
@@ -411,7 +411,7 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
|
||||
* @return boolean
|
||||
*/
|
||||
protected function running_javascript() {
|
||||
return get_class($this->getSession()->getDriver()) === 'Moodle\BehatExtension\Driver\MoodleSelenium2Driver';
|
||||
return get_class($this->getSession()->getDriver()) !== 'Behat\Mink\Driver\GoutteDriver';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class behat_form_field {
|
||||
global $CFG;
|
||||
|
||||
// Textareas are considered text based elements.
|
||||
$tagname = $this->field->getTagName();
|
||||
$tagname = strtolower($this->field->getTagName());
|
||||
if ($tagname == 'textarea') {
|
||||
return false;
|
||||
}
|
||||
@@ -131,11 +131,13 @@ class behat_form_field {
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Select tag.
|
||||
if ($tagname == 'select') {
|
||||
} else if ($tagname == 'select') {
|
||||
// Select tag.
|
||||
$classname = 'behat_form_select';
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$classpath = $CFG->dirroot . '/lib/behat/form_field/' . $classname . '.php';
|
||||
@@ -143,4 +145,13 @@ class behat_form_field {
|
||||
return new $classname($this->session, $this->field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the scenario is running in a browser that can run Javascript or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function running_javascript() {
|
||||
return get_class($this->session->getDriver()) !== 'Behat\Mink\Driver\GoutteDriver';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,26 @@ class behat_form_select extends behat_form_field {
|
||||
*/
|
||||
public function set_value($value) {
|
||||
$this->field->selectOption($value);
|
||||
|
||||
// Adding a click as Selenium requires it to fire some JS events.
|
||||
if ($this->running_javascript()) {
|
||||
|
||||
// Single select needs an extra click in the option.
|
||||
if (!$this->field->hasAttribute('multiple')) {
|
||||
// Using the driver direcly because Element methods are messy when dealing
|
||||
// with elements inside containers.
|
||||
$optionxpath = $this->field->getXpath() .
|
||||
"/descendant::option[(./@value = '" . $value . "' or contains(normalize-space(string(.)), '" . $value . "'))]";
|
||||
$optionnodes = $this->session->getDriver()->find($optionxpath);
|
||||
if ($optionnodes) {
|
||||
current($optionnodes)->click();
|
||||
}
|
||||
|
||||
} else {
|
||||
// Multiple ones needs the click in the select.
|
||||
$this->field->click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -178,7 +178,16 @@ class behat_forms extends behat_base {
|
||||
|
||||
// Adding a click as Selenium requires it to fire some JS events.
|
||||
if ($this->running_javascript()) {
|
||||
$selectnode->click();
|
||||
|
||||
if (!$selectnode->hasAttribute('multiple')) {
|
||||
// Single select needs an extra click in the option.
|
||||
$xpath = ".//option[(./@value = '" . $option . "' or contains(normalize-space(string(.)), '" . $option . "'))]";
|
||||
$optionnode = $this->find('xpath', $xpath, false, $selectnode);
|
||||
$optionnode->click();
|
||||
} else {
|
||||
// Multiple ones needs the click in the select.
|
||||
$selectnode->click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,9 +170,22 @@ class behat_hooks extends behat_base {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait until the page is ready.
|
||||
try {
|
||||
$this->getSession()->wait(self::TIMEOUT * 1000, '(document.readyState === "complete")');
|
||||
// Wait until the page is ready.
|
||||
// We are already checking that we use a JS browser, this could
|
||||
// change in case we use another JS driver.
|
||||
try {
|
||||
|
||||
// Safari and Internet Explorer requires time between steps,
|
||||
// otherwise Selenium tries to click in the previous page's DOM.
|
||||
if ($this->getSession()->getDriver()->getBrowserName() == 'safari' ||
|
||||
$this->getSession()->getDriver()->getBrowserName() == 'internet explorer') {
|
||||
$this->getSession()->wait(self::TIMEOUT * 1000, false);
|
||||
|
||||
} else {
|
||||
// With other browsers we just wait for the DOM ready.
|
||||
$this->getSession()->wait(self::TIMEOUT * 1000, '(document.readyState === "complete")');
|
||||
}
|
||||
|
||||
} catch (NoSuchWindow $e) {
|
||||
// If we were interacting with a popup window it will not exists after closing it.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user