Skip to content

Commit

Permalink
MDL-66457 behat: simplify selector search
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Aug 30, 2019
1 parent 2baf9a8 commit 2bfb885
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions lib/behat/behat_base.php
Expand Up @@ -185,27 +185,7 @@ function($context, $args) {
return $context->getSession()->getPage()->findAll($args['selector'], $args['locator']);
}

// For nodes contained in other nodes we can not use the basic named selectors
// as they include unions and they would look for matches in the DOM root.
$elementxpath = $context->getSession()->getSelectorsHandler()->selectorToXpath($args['selector'], $args['locator']);

// Split the xpath in unions and prefix them with the container xpath.
$unions = explode('|', $elementxpath);
foreach ($unions as $key => $union) {
$union = trim($union);

// We are in the container node.
if (strpos($union, '.') === 0) {
$union = substr($union, 1);
} else if (strpos($union, '/') !== 0) {
// Adding the path separator in case it is not there.
$union = '/' . $union;
}
$unions[$key] = $args['node']->getXpath() . $union;
}

// We can not use usual Element::find() as it prefixes with DOM root.
return $context->getSession()->getDriver()->find(implode('|', $unions));
return $args['node']->findAll($args['selector'], $args['locator']);
},
$params,
$timeout,
Expand Down

0 comments on commit 2bfb885

Please sign in to comment.