Commit ea5dfe65 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

MDL-69136 behat: Improve reliability of navigation steps

parent 1dd40077
...@@ -194,7 +194,7 @@ class behat_navigation extends behat_base { ...@@ -194,7 +194,7 @@ class behat_navigation extends behat_base {
// We just want to expand the node, we don't want to follow it. // We just want to expand the node, we don't want to follow it.
$node = $node->getParent(); $node = $node->getParent();
} }
$node->click(); $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
} }
/** /**
...@@ -218,7 +218,7 @@ class behat_navigation extends behat_base { ...@@ -218,7 +218,7 @@ class behat_navigation extends behat_base {
// We just want to expand the node, we don't want to follow it. // We just want to expand the node, we don't want to follow it.
$node = $node->getParent(); $node = $node->getParent();
} }
$node->click(); $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
} }
/** /**
...@@ -245,7 +245,7 @@ class behat_navigation extends behat_base { ...@@ -245,7 +245,7 @@ class behat_navigation extends behat_base {
// don't wait, it is non-JS and we already waited for the DOM. // don't wait, it is non-JS and we already waited for the DOM.
$siteadminlink = $this->getSession()->getPage()->find('named_exact', array('link', "'" . $siteadminstr . "'")); $siteadminlink = $this->getSession()->getPage()->find('named_exact', array('link', "'" . $siteadminstr . "'"));
if ($siteadminlink) { if ($siteadminlink) {
$siteadminlink->click(); $this->execute('behat_general::i_click_on', [$siteadminlink, 'NodeElement']);
} }
} }
} }
...@@ -302,7 +302,7 @@ class behat_navigation extends behat_base { ...@@ -302,7 +302,7 @@ class behat_navigation extends behat_base {
throw new ExpectationException('Navigation node "' . $nodetext . '" not found under "' . throw new ExpectationException('Navigation node "' . $nodetext . '" not found under "' .
implode($parentnodes, ' > ') . '"', $this->getSession()); implode($parentnodes, ' > ') . '"', $this->getSession());
} }
$nodetoclick->click(); $this->execute('behat_general::i_click_on', [$nodetoclick, 'NodeElement']);
} }
/** /**
...@@ -791,9 +791,8 @@ class behat_navigation extends behat_base { ...@@ -791,9 +791,8 @@ class behat_navigation extends behat_base {
$node = $this->find('xpath', $xpath); $node = $this->find('xpath', $xpath);
$expanded = $node->getAttribute('aria-expanded'); $expanded = $node->getAttribute('aria-expanded');
if ($expanded === 'false') { if ($expanded === 'false') {
$node->click(); $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
$this->ensure_node_attribute_is_set($node, 'aria-expanded', 'true'); $this->ensure_node_attribute_is_set($node, 'aria-expanded', 'true');
$this->wait_for_pending_js();
} }
} }
...@@ -812,8 +811,7 @@ class behat_navigation extends behat_base { ...@@ -812,8 +811,7 @@ class behat_navigation extends behat_base {
$node = $this->find('xpath', $xpath); $node = $this->find('xpath', $xpath);
$expanded = $node->getAttribute('aria-expanded'); $expanded = $node->getAttribute('aria-expanded');
if ($expanded === 'true') { if ($expanded === 'true') {
$node->click(); $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
$this->wait_for_pending_js();
} }
} }
...@@ -835,8 +833,8 @@ class behat_navigation extends behat_base { ...@@ -835,8 +833,8 @@ class behat_navigation extends behat_base {
protected function go_to_main_course_page() { protected function go_to_main_course_page() {
$url = $this->getSession()->getCurrentUrl(); $url = $this->getSession()->getCurrentUrl();
if (!preg_match('|/course/view.php\?id=[\d]+$|', $url)) { if (!preg_match('|/course/view.php\?id=[\d]+$|', $url)) {
$this->find('xpath', '//header//div[@id=\'page-navbar\']//a[contains(@href,\'/course/view.php?id=\')]')->click(); $node = $this->find('xpath', '//header//div[@id=\'page-navbar\']//a[contains(@href,\'/course/view.php?id=\')]');
$this->execute('behat_general::wait_until_the_page_is_ready'); $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
} }
} }
...@@ -856,8 +854,8 @@ class behat_navigation extends behat_base { ...@@ -856,8 +854,8 @@ class behat_navigation extends behat_base {
$tabxpath = '//ul[@role=\'tablist\']/li/a[contains(normalize-space(.), ' . $tabname . ')]'; $tabxpath = '//ul[@role=\'tablist\']/li/a[contains(normalize-space(.), ' . $tabname . ')]';
if ($node = $this->getSession()->getPage()->find('xpath', $tabxpath)) { if ($node = $this->getSession()->getPage()->find('xpath', $tabxpath)) {
if ($this->running_javascript()) { if ($this->running_javascript()) {
$this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
// Click on the tab and add 'active' tab to the xpath. // Click on the tab and add 'active' tab to the xpath.
$node->click();
$xpath .= '//div[contains(@class,\'active\')]'; $xpath .= '//div[contains(@class,\'active\')]';
} else { } else {
// Add the tab content selector to the xpath. // Add the tab content selector to the xpath.
...@@ -881,8 +879,7 @@ class behat_navigation extends behat_base { ...@@ -881,8 +879,7 @@ class behat_navigation extends behat_base {
if (!$node = $this->getSession()->getPage()->find('xpath', $xpath)) { if (!$node = $this->getSession()->getPage()->find('xpath', $xpath)) {
throw new ElementNotFoundException($this->getSession(), 'Link "' . join(' > ', $nodelist) . '"'); throw new ElementNotFoundException($this->getSession(), 'Link "' . join(' > ', $nodelist) . '"');
} }
$node->click(); $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
$this->wait_for_pending_js();
} }
/** /**
...@@ -929,8 +926,8 @@ class behat_navigation extends behat_base { ...@@ -929,8 +926,8 @@ class behat_navigation extends behat_base {
$menuxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu(); $menuxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu();
} }
if ($menuxpath && $this->running_javascript()) { if ($menuxpath && $this->running_javascript()) {
$this->find('xpath', $menuxpath . '//a[@data-toggle=\'dropdown\']')->click(); $node = $this->find('xpath', $menuxpath . '//a[@data-toggle=\'dropdown\']');
$this->wait_for_pending_js(); $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
} }
} }
...@@ -952,15 +949,14 @@ class behat_navigation extends behat_base { ...@@ -952,15 +949,14 @@ class behat_navigation extends behat_base {
$isheader = false; $isheader = false;
} }
$this->toggle_page_administration_menu($menuxpath); $this->execute('behat_navigation::toggle_page_administration_menu', [$menuxpath]);
if (!$isheader || count($nodelist) == 1) { if (!$isheader || count($nodelist) == 1) {
$lastnode = end($nodelist); $lastnode = end($nodelist);
$linkname = behat_context_helper::escape($lastnode); $linkname = behat_context_helper::escape($lastnode);
$link = $this->getSession()->getPage()->find('xpath', $menuxpath . '//a[contains(normalize-space(.), ' . $linkname . ')]'); $link = $this->getSession()->getPage()->find('xpath', $menuxpath . '//a[contains(normalize-space(.), ' . $linkname . ')]');
if ($link) { if ($link) {
$link->click(); $this->execute('behat_general::i_click_on', [$link, 'NodeElement']);
$this->wait_for_pending_js();
return; return;
} }
} }
...@@ -970,8 +966,7 @@ class behat_navigation extends behat_base { ...@@ -970,8 +966,7 @@ class behat_navigation extends behat_base {
$linkname = behat_context_helper::escape(get_string('morenavigationlinks')); $linkname = behat_context_helper::escape(get_string('morenavigationlinks'));
$link = $this->getSession()->getPage()->find('xpath', $menuxpath . '//a[contains(normalize-space(.), ' . $linkname . ')]'); $link = $this->getSession()->getPage()->find('xpath', $menuxpath . '//a[contains(normalize-space(.), ' . $linkname . ')]');
if ($link) { if ($link) {
$link->click(); $this->execute('behat_general::i_click_on', [$link, 'NodeElement']);
$this->execute('behat_general::wait_until_the_page_is_ready');
$this->select_on_administration_page($nodelist); $this->select_on_administration_page($nodelist);
return; return;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment