From dea76f367c7986090aad06a016c5bfed3258be99 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 2 Feb 2016 10:06:25 +0800 Subject: [PATCH] MDL-52970 behat: Navigation step improvement If navigation node to expand is a link then first click on it and navigate to next page where it is expanded, and then click on link within. This is needed as some drivers click on link and don't open the navigation node which are links --- lib/tests/behat/behat_navigation.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 4d96310b409..8b7ff9c7ad8 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -262,7 +262,20 @@ class behat_navigation extends behat_base { $nodetoexpand = $node->find('xpath', $xpath); $this->ensure_node_is_visible($nodetoexpand); - $nodetoexpand->click(); + + // If node is a link then some driver click in the middle of the node, which click on link and + // page gets redirected. To ensure expansion works in all cases, check if the node to expand is a + // link and if yes then click on link and wait for it to navigate to next page with node expanded. + $nodetoexpandliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($parentnodes[$i]); + $nodetoexpandxpathlink = $xpath . "/a[normalize-space(.)=" . $nodetoexpandliteral . "]"; + + if ($nodetoexpandlink = $node->find('xpath', $nodetoexpandxpathlink)) { + $behatgeneralcontext = behat_context_helper::get('behat_general'); + $nodetoexpandlink->click(); + $behatgeneralcontext->wait_until_the_page_is_ready(); + } else { + $nodetoexpand->click(); + } // Wait for node to load, if not loaded before. if ($nodetoexpand->hasAttribute('data-loaded') && $nodetoexpand->getAttribute('data-loaded') == 0) {