diff --git a/lib/behat/classes/behat_session_trait.php b/lib/behat/classes/behat_session_trait.php index 7d5bedec482..41f2e88db5f 100644 --- a/lib/behat/classes/behat_session_trait.php +++ b/lib/behat/classes/behat_session_trait.php @@ -440,13 +440,12 @@ trait behat_session_trait { if ($containerselectortype === 'NodeElement' && is_a($containerelement, NodeElement::class)) { // Support a NodeElement being passed in for use in step chaining. $containernode = $containerelement; - $locatorexceptionmsg = $element; } else { // Gets the container, it will always be text based. $containernode = $this->get_text_selector_node($containerselectortype, $containerelement); - $locatorexceptionmsg = $element . '" in the "' . $containerelement. '" "' . $containerselectortype. '"'; } + $locatorexceptionmsg = $element . '" in the "' . $this->get_selector_description($containerselectortype, $containerelement); $exception = new ElementNotFoundException($this->getSession(), $selectortype, null, $locatorexceptionmsg); return $this->find($selectortype, $element, $exception, $containernode); diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 8d89224db91..8b6f84dc090 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -28,6 +28,7 @@ require_once(__DIR__ . '/../../behat/behat_base.php'); use Behat\Gherkin\Node\TableNode; +use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\DriverException; use Behat\Mink\Exception\ElementNotFoundException; use Behat\Mink\Exception\ExpectationException; @@ -1162,20 +1163,12 @@ EOF; * @throws ElementNotFoundException Thrown by behat_base::find * @param string $element The locator of the specified selector * @param string $selectortype The selector type - * @param string $containerelement The container selector type - * @param string $containerselectortype The container locator + * @param NodeElement|string $containerelement The locator of the container selector + * @param string $containerselectortype The container selector type */ public function should_exist_in_the($element, $selectortype, $containerelement, $containerselectortype) { - // Get the container node. - $containernode = $this->find($containerselectortype, $containerelement); - - // Specific exception giving info about where can't we find the element. - $containerdescription = $this->get_selector_description($containerselectortype, $containerelement); - $locatorexceptionmsg = "{$element} not found in the {$containerdescription}}"; - $exception = new ElementNotFoundException($this->getSession(), $selectortype, null, $locatorexceptionmsg); - - // Looks for the requested node inside the container node. - $this->find($selectortype, $element, $exception, $containernode); + // Will throw an ElementNotFoundException if it does not exist. + $this->get_node_in_container($selectortype, $element, $containerselectortype, $containerelement); } /** @@ -1187,8 +1180,8 @@ EOF; * @throws ExpectationException * @param string $element The locator of the specified selector * @param string $selectortype The selector type - * @param string $containerelement The container selector type - * @param string $containerselectortype The container locator + * @param NodeElement|string $containerelement The locator of the container selector + * @param string $containerselectortype The container selector type */ public function should_not_exist_in_the($element, $selectortype, $containerelement, $containerselectortype) { // Get the container node.