diff --git a/lib/behat/classes/behat_session_trait.php b/lib/behat/classes/behat_session_trait.php index 8715fc810e1..a9377bfc818 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 6e1e26f8a13..dbce60b922d 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; @@ -1217,20 +1218,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); } /** @@ -1242,8 +1235,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. diff --git a/mod/quiz/tests/behat/quiz_question_versions.feature b/mod/quiz/tests/behat/quiz_question_versions.feature index 189602e01fc..96c84ad0c7c 100644 --- a/mod/quiz/tests/behat/quiz_question_versions.feature +++ b/mod/quiz/tests/behat/quiz_question_versions.feature @@ -34,7 +34,7 @@ Feature: Quiz question versioning Then I should see "First question" And I should see "Answer the first question" And the field "version" matches value "Always latest" - And "v1 (latest)" "option" should exist in the "version" "select" + And the "version" select box should contain "v1 (latest)" # We check that the corresponding version is the appropriate one in preview And I click on "Preview question" "link" And I switch to "questionpreview" window @@ -54,7 +54,7 @@ Feature: Quiz question versioning | Correct answer | False | And I press "id_submitbutton" And the field "version" matches value "Always latest" - And "v1" "option" should exist in the "version" "select" + And the "version" select box should contain "v1" And I set the field "version" to "v2 (latest)" Then I should see "First question (v2)" And I should see "Answer the new first question" @@ -79,9 +79,9 @@ Feature: Quiz question versioning Then I should see "First question" And I should see "Answer the first question" And the field "version" matches value "Always latest" - And "v1 (latest)" "option" should exist in the "version" "select" - And "v2" "option" should not exist in the "version" "select" - And "v2 (latest)" "option" should not exist in the "version" "select" + And the "version" select box should contain "v1 (latest)" + And the "version" select box should not contain "v2" + And the "version" select box should not contain "v2 (latest)" And I am on the "Quiz 1" "mod_quiz > View" page And I press "Preview quiz" And I should see "Answer the first question" diff --git a/question/bank/managecategories/tests/behat/question_categories.feature b/question/bank/managecategories/tests/behat/question_categories.feature index 217754e092b..f26939346c9 100644 --- a/question/bank/managecategories/tests/behat/question_categories.feature +++ b/question/bank/managecategories/tests/behat/question_categories.feature @@ -42,7 +42,7 @@ Feature: A teacher can put questions in categories in the question bank And I should see "(0)" And I should see "Created for testing category, HTML entity & its encoding" in the "'Test' & 'display'" "list_item" And I follow "Add category" - And "'Test' & 'display' [newcatidnumber]" "option" should exist in the "Parent category" "select" + And the "Parent category" select box should contain "'Test' & 'display' [newcatidnumber]" Scenario: A question category can be edited When I am on the "Course 1" "core_question > course question categories" page