Commit 0398e25b authored by Son Nguyen's avatar Son Nguyen
Browse files

Fix deprecated 'named' selector and implement 2 steps

- I follow "link" in the "element" "selector"
- I press "button" in the "element" "selector"

Change-Id: I509214a2a38e1a6b43344bf811380db552fcdfc2
parent 9ff33b3d
...@@ -116,12 +116,16 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext { ...@@ -116,12 +116,16 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
*/ */
protected function find_all($selector, $locator, $exception = false, $node = false) { protected function find_all($selector, $locator, $exception = false, $node = false) {
// Fix deprecated selector
if ($selector === 'named') {
$selector = $selector . '_partial';
}
// Generic info. // Generic info.
if (!$exception) { if (!$exception) {
// With named selectors we can be more specific. // With named selectors we can be more specific.
if ($selector == 'named') { if ($selector === 'named_partial') {
$selector = $selector . '_partial';
$exceptiontype = $locator[0]; $exceptiontype = $locator[0];
$exceptionlocator = $locator[1]; $exceptionlocator = $locator[1];
...@@ -140,6 +144,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext { ...@@ -140,6 +144,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
} }
$params = array('selector' => $selector, 'locator' => $locator); $params = array('selector' => $selector, 'locator' => $locator);
// Pushing $node if required. // Pushing $node if required.
if ($node) { if ($node) {
$params['node'] = $node; $params['node'] = $node;
...@@ -160,7 +165,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext { ...@@ -160,7 +165,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
// Split the xpath in unions and prefix them with the container xpath. // Split the xpath in unions and prefix them with the container xpath.
$unions = explode('|', $elementxpath); $unions = explode('|', $elementxpath);
foreach ($unions as $key => $union) { foreach ($unions as &$union) {
$union = trim($union); $union = trim($union);
// We are in the container node. // We are in the container node.
...@@ -171,7 +176,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext { ...@@ -171,7 +176,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
// Adding the path separator in case it is not there. // Adding the path separator in case it is not there.
$union = '/' . $union; $union = '/' . $union;
} }
$unions[$key] = $args['node']->getXpath() . $union; $union = $args['node']->getXpath() . $union;
} }
// We can not use usual Element::find() as it prefixes with DOM root. // We can not use usual Element::find() as it prefixes with DOM root.
...@@ -378,7 +383,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext { ...@@ -378,7 +383,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
list($selector, $locator) = $this->transform_selector($selectortype, $element); list($selector, $locator) = $this->transform_selector($selectortype, $element);
// Specific exception giving info about where can't we find the element. // Specific exception giving info about where can't we find the element.
$locatorexceptionmsg = $element . '" in the "' . $containerelement. '" "' . $containerselectortype. '"'; $locatorexceptionmsg = "'$element' in the '{$containerelement}' '{$containerselectortype}'";
$exception = new ElementNotFoundException($this->getSession(), $selectortype, null, $locatorexceptionmsg); $exception = new ElementNotFoundException($this->getSession(), $selectortype, null, $locatorexceptionmsg);
// Looks for the requested node inside the container node. // Looks for the requested node inside the container node.
......
...@@ -317,6 +317,36 @@ class BehatGeneral extends BehatBase { ...@@ -317,6 +317,36 @@ class BehatGeneral extends BehatBase {
$node->click(); $node->click();
} }
/**
* Follow the link which is located inside the second element.
*
* @When /^I follow "(?P<link>(?:[^"]|\\")*)" in the "(?P<element_container_string>(?:[^"]|\\")*)" "(?P<text_selector_string>[^"]*)"$/
* @param string $link we look for
* @param string $nodeelement Element we look in
* @param string $nodeselectortype The type of selector where we look in
*/
public function i_follow_in_the($link, $nodeelement, $nodeselectortype) {
$node = $this->get_node_in_container('link', $link, $nodeselectortype, $nodeelement);
$this->ensure_node_is_visible($node);
$node->click();
}
/**
* Press a button which is located inside the second element.
*
* @When /^I press "(?P<button>(?:[^"]|\\")*)" in the "(?P<element_container_string>(?:[^"]|\\")*)" "(?P<text_selector_string>[^"]*)"$/
* @param string $button we look for
* @param string $nodeelement Element we look in
* @param string $nodeselectortype The type of selector where we look in
*/
public function i_press_in_the($button, $nodeelement, $nodeselectortype) {
$node = $this->get_node_in_container('button', $button, $nodeselectortype, $nodeelement);
$this->ensure_node_is_visible($node);
$node->click();
}
/** /**
* Click on the link or button inside a list/table row containing the specified text. * Click on the link or button inside a list/table row containing the specified text.
* *
......
Markdown is supported
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