Permalink
Browse files

Merge branch 'MDL-58948_chrome_mink_driver' of https://github.com/mrm…

  • Loading branch information...
dmonllao committed Jul 17, 2017
2 parents 05c616d + b095b36 commit 3ea76efa00dd3b56c301053be1dda2e2771e2056
@@ -66,7 +66,7 @@ public function i_add_comment_to_comments_block($comment) {
$this->find_link(get_string('savecomment'))->click();
// Delay after clicking so that additional comments will have unique time stamps.
// We delay 1 second which is all we need.
$this->getSession()->wait(1000, false);
$this->getSession()->wait(1000);
} else {
@@ -104,7 +104,7 @@ public function i_delete_comment_from_comments_block($comment) {
);
// Wait for the animation to finish, in theory is just 1 sec, adding 4 just in case.
$this->getSession()->wait(4 * 1000, false);
$this->getSession()->wait(4 * 1000);
}
}
@@ -1830,7 +1830,7 @@ public function i_toggle_category_children_visibility_in_frontpage($categoryname
$node->click();
// Smooth expansion.
$this->getSession()->wait(1000, false);
$this->getSession()->wait(1000);
}
/**
@@ -279,7 +279,7 @@ Console.prototype = {
if (!this.categoriesinit) {
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'a[data-action]', this);
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'input[name="bcat[]"]', this);
this.get('categorylisting').delegate('click', this.handleBulkSortByaction, '#menuselectsortby', this);
this.get('categorylisting').delegate('change', this.handleBulkSortByaction, '#menuselectsortby', this);
this.categoriesinit = true;
Y.log(count + ' categories being managed', 'info', 'moodle-course-management');
} else {

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -278,7 +278,7 @@ Console.prototype = {
if (!this.categoriesinit) {
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'a[data-action]', this);
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'input[name="bcat[]"]', this);
this.get('categorylisting').delegate('click', this.handleBulkSortByaction, '#menuselectsortby', this);
this.get('categorylisting').delegate('change', this.handleBulkSortByaction, '#menuselectsortby', this);
this.categoriesinit = true;
} else {
}
@@ -277,7 +277,7 @@ Console.prototype = {
if (!this.categoriesinit) {
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'a[data-action]', this);
this.get('categorylisting').delegate('click', this.handleCategoryDelegation, 'input[name="bcat[]"]', this);
this.get('categorylisting').delegate('click', this.handleBulkSortByaction, '#menuselectsortby', this);
this.get('categorylisting').delegate('change', this.handleBulkSortByaction, '#menuselectsortby', this);
this.categoriesinit = true;
Y.log(count + ' categories being managed', 'info', 'moodle-course-management');
} else {
@@ -62,8 +62,11 @@ public function i_add_user_to_group_members($userfullname, $groupname) {
$select->selectOption($fulloption);
// This is needed by some drivers to ensure relevant event is triggred and button is enabled.
$script = "Syn.trigger('change', {}, {{ELEMENT}})";
$this->getSession()->getDriver()->triggerSynScript($select->getXpath(), $script);
$driver = $this->getSession()->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
$script = "Syn.trigger('change', {}, {{ELEMENT}})";
$driver->triggerSynScript($select->getXpath(), $script);
}
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
// Here we don't need to wait for the AJAX response.
@@ -28,7 +28,8 @@
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
use Behat\Mink\Exception\ExpectationException as ExpectationException,
use Behat\Mink\Exception\DriverException,
Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Element\NodeElement as NodeElement;
@@ -335,8 +336,6 @@ protected function spin($lambda, $args = false, $timeout = false, $exception = f
if (!$exception) {
$exception = $e;
}
// We wait until no exception is thrown or timeout expires.
continue;
}
if ($this->running_javascript()) {
@@ -727,7 +726,7 @@ public function wait_for_pending_js() {
$pending = '';
try {
$jscode = '
return function() {
return (function() {
if (typeof M === "undefined") {
if (document.readyState === "complete") {
return "";
@@ -741,7 +740,7 @@ public function wait_for_pending_js() {
} else {
return "incomplete"
}
}();';
}());';
$pending = $this->getSession()->evaluateScript($jscode);
} catch (NoSuchWindow $nsw) {
// We catch an exception here, in case we just closed the window we were interacting with.
@@ -883,6 +882,8 @@ public function look_for_exceptions() {
} catch (NoSuchWindow $e) {
// If we were interacting with a popup window it will not exists after closing it.
} catch (DriverException $e) {
// Same reason as above.
}
}
@@ -959,7 +960,12 @@ protected function js_trigger_click($node) {
}
$this->ensure_node_is_visible($node); // Ensures hidden elements can't be clicked.
$xpath = $node->getXpath();
$script = "Syn.click({{ELEMENT}})";
$this->getSession()->getDriver()->triggerSynScript($xpath, $script);
$driver = $this->getSession()->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
$script = "Syn.click({{ELEMENT}})";
$driver->triggerSynScript($xpath, $script);
} else {
$driver->click($xpath);
}
}
}
@@ -108,9 +108,12 @@ public function matches($expectedvalue = false) {
* Trigger on change event.
*/
protected function trigger_on_change() {
$this->session->getDriver()->triggerSynScript(
$this->field->getXPath(),
"Syn.trigger('change', {}, {{ELEMENT}})"
);
$driver = $this->session->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
$driver->triggerSynScript(
$this->field->getXPath(),
"Syn.trigger('change', {}, {{ELEMENT}})"
);
}
}
}
@@ -114,6 +114,8 @@ public function key_press($char, $modifier = null) {
// If the JS handler attached to keydown or keypress destroys the element
// the later events may trigger errors because form element no longer exist
// or is not visible. Ignore such exceptions here.
} catch (\Behat\Mink\Exception\ElementNotFoundException $e) {
// Other Mink drivers can throw this for the same reason as above.
}
}
@@ -78,8 +78,11 @@ public function set_value($value) {
if (!$node = $this->session->getDriver()->find($dialoguexpath)) {
$script = "Syn.trigger('change', {}, {{ELEMENT}})";
try {
$this->session->getDriver()->triggerSynScript($this->field->getXpath(), $script);
$this->session->getDriver()->click('//body//div[@class="skiplinks"]');
$driver = $this->session->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
$driver->triggerSynScript($this->field->getXpath(), $script);
}
$driver->click('//body//div[@class="skiplinks"]');
} catch (\Exception $e) {
return;
}
@@ -148,13 +148,20 @@ protected function expand_all_fields() {
return;
}
// Funny thing about this, with findAll() we specify a pattern and each element matching the pattern is added to the array
// with of xpaths with a [0], [1]... sufix, but when we click on an element it does not matches the specified xpath
// anymore (now is a "Show less..." link) so [1] becomes [0], that's why we always click on the first XPath match,
// will be always the next one.
$iterations = count($showmores);
for ($i = 0; $i < $iterations; $i++) {
$showmores[0]->click();
if ($this->getSession()->getDriver() instanceof \DMore\ChromeDriver\ChromeDriver) {
// Chrome Driver produces unique xpaths for each element.
foreach ($showmores as $showmore) {
$showmore->click();
}
} else {
// Funny thing about this, with findAll() we specify a pattern and each element matching the pattern
// is added to the array with of xpaths with a [0], [1]... sufix, but when we click on an element it
// does not matches the specified xpath anymore (now is a "Show less..." link) so [1] becomes [0],
// that's why we always click on the first XPath match, will be always the next one.
$iterations = count($showmores);
for ($i = 0; $i < $iterations; $i++) {
$showmores[0]->click();
}
}
} catch (ElementNotFoundException $e) {
@@ -143,7 +143,7 @@ public function i_wait_to_be_redirected() {
// Wait until the URL change is executed.
if ($this->running_javascript()) {
$this->getSession()->wait($waittime * 1000, false);
$this->getSession()->wait($waittime * 1000);
} else if (!empty($url)) {
// We redirect directly as we can not wait for an automatic redirection.
@@ -253,7 +253,7 @@ public function click_link($link) {
*/
public function i_wait_seconds($seconds) {
if ($this->running_javascript()) {
$this->getSession()->wait($seconds * 1000, false);
$this->getSession()->wait($seconds * 1000);
} else {
sleep($seconds);
}
@@ -634,6 +634,9 @@ function($context, $args) {
} catch (WebDriver\Exception\NoSuchElement $e) {
// Do nothing just return, as element is no more on page.
return true;
} catch (ElementNotFoundException $e) {
// Do nothing just return, as element is no more on page.
return true;
}
}
@@ -1610,7 +1613,12 @@ public function i_post_tab_key_in_element($element, $selectortype) {
}
// Gets the node based on the requested selector type and locator.
$node = $this->get_selected_node($selectortype, $element);
$this->getSession()->getDriver()->post_key("\xEE\x80\x84", $node->getXpath());
$driver = $this->getSession()->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
$driver->post_key("\xEE\x80\x84", $node->getXpath());
} else {
$driver->keyDown($node->getXpath(), "\t");
}
}
/**

0 comments on commit 3ea76ef

Please sign in to comment.