diff --git a/grade/grading/tests/behat/behat_grading.php b/grade/grading/tests/behat/behat_grading.php index 1847d07c1fc..3841dbe150f 100644 --- a/grade/grading/tests/behat/behat_grading.php +++ b/grade/grading/tests/behat/behat_grading.php @@ -85,7 +85,7 @@ class behat_grading extends behat_base { // Step to access the user grade page from the grading page. $gradetext = get_string('gradeverb'); - $this->execute('behat_general::click_link', $this->escape($activityname)); + $this->execute('behat_navigation::go_to_breadcrumb_location', $this->escape($activityname)); $this->execute('behat_navigation::i_navigate_to_in_current_page_administration', get_string('viewgrading', 'mod_assign')); diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 053010c6b0e..6279c1b9275 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -1065,4 +1065,20 @@ class behat_navigation extends behat_base { } $this->execute('behat_general::i_visit', [$url]); } + + + /** + * First checks to see if we are on this page via the breadcrumb. If not we then attempt to follow the link name given. + * + * @param string $pagename Name of the breadcrumb item to check and follow. + */ + public function go_to_breadcrumb_location(string $pagename): void { + $link = $this->getSession()->getPage()->find( + 'xpath', + "//nav[@aria-label='Navigation bar']/ol/li[last()][contains(normalize-space(.), '" . $pagename . "')]" + ); + if (!$link) { + $this->execute("behat_general::click_link", $pagename); + } + } } diff --git a/mod/choice/tests/behat/behat_mod_choice.php b/mod/choice/tests/behat/behat_mod_choice.php index 2ba915656b7..f35d02e52f3 100644 --- a/mod/choice/tests/behat/behat_mod_choice.php +++ b/mod/choice/tests/behat/behat_mod_choice.php @@ -46,7 +46,7 @@ class behat_mod_choice extends behat_base { * @return array */ public function I_choose_option_from_activity($option, $choiceactivity) { - $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($choiceactivity), 'choice activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $this->escape($choiceactivity)); $this->execute('behat_forms::i_set_the_field_to', array( $this->escape($option), 1)); @@ -68,7 +68,7 @@ class behat_mod_choice extends behat_base { $behatforms = behat_context_helper::get('behat_forms'); // Go to choice activity. - $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($choiceactivity), 'choice activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $this->escape($choiceactivity)); // Wait for page to be loaded. $this->wait_for_pending_js(); diff --git a/mod/data/tests/behat/behat_mod_data.php b/mod/data/tests/behat/behat_mod_data.php index 1f59bc6cc5d..ce9748ffbd2 100644 --- a/mod/data/tests/behat/behat_mod_data.php +++ b/mod/data/tests/behat/behat_mod_data.php @@ -48,7 +48,7 @@ class behat_mod_data extends behat_base { * @param TableNode $fielddata */ public function i_add_a_field_to_database_and_i_fill_the_form_with($fieldtype, $activityname, TableNode $fielddata) { - $this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($activityname), 'data activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $this->escape($activityname)); // Open "Fields" tab if it is not already open. $fieldsstr = get_string('fields', 'mod_data'); diff --git a/mod/forum/tests/behat/behat_mod_forum.php b/mod/forum/tests/behat/behat_mod_forum.php index f6025b6ec62..28150162b98 100644 --- a/mod/forum/tests/behat/behat_mod_forum.php +++ b/mod/forum/tests/behat/behat_mod_forum.php @@ -113,7 +113,7 @@ class behat_mod_forum extends behat_base { */ public function i_reply_post_from_forum_using_an_inpage_reply_with($postsubject, $forumname, TableNode $table) { // Navigate to forum. - $this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($forumname), 'forum activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $this->escape($forumname)); $this->execute('behat_general::click_link', $this->escape($postsubject)); $this->execute('behat_general::click_link', get_string('reply', 'forum')); @@ -132,7 +132,7 @@ class behat_mod_forum extends behat_base { */ public function i_navigate_to_post_in_forum($postsubject, $forumname) { // Navigate to forum discussion. - $this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($forumname), 'forum activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $this->escape($forumname)); $this->execute('behat_general::click_link', $this->escape($postsubject)); } @@ -474,7 +474,7 @@ class behat_mod_forum extends behat_base { */ protected function add_new_discussion($forumname, TableNode $table, $buttonstr) { // Navigate to forum. - $this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($forumname), 'forum activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $this->escape($forumname)); $this->execute('behat_general::click_link', $buttonstr); $this->execute('behat_forms::press_button', get_string('showadvancededitor')); @@ -493,7 +493,7 @@ class behat_mod_forum extends behat_base { */ protected function add_new_discussion_inline($forumname, TableNode $table, $buttonstr) { // Navigate to forum. - $this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($forumname), 'forum activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $this->escape($forumname)); $this->execute('behat_general::click_link', $buttonstr); $this->fill_new_discussion_form($table); } diff --git a/mod/glossary/tests/behat/behat_mod_glossary.php b/mod/glossary/tests/behat/behat_mod_glossary.php index bf84100a699..9ff7c2afb12 100644 --- a/mod/glossary/tests/behat/behat_mod_glossary.php +++ b/mod/glossary/tests/behat/behat_mod_glossary.php @@ -61,7 +61,7 @@ class behat_mod_glossary extends behat_base { */ public function i_add_a_glossary_entries_category_named($categoryname) { - $this->execute("behat_general::click_link", get_string('categoryview', 'mod_glossary')); + $this->execute("behat_navigation::go_to_breadcrumb_location", get_string('categoryview', 'mod_glossary')); $this->execute("behat_forms::press_button", get_string('editcategories', 'mod_glossary')); diff --git a/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php b/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php index 4ad7fd94bf1..bc33974f6b4 100644 --- a/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php +++ b/mod/workshop/allocation/manual/tests/behat/behat_workshopallocation_manual.php @@ -87,7 +87,7 @@ class behat_workshopallocation_manual extends behat_base { * @param TableNode $table should have one column with title 'Reviewer' and another with title 'Participant' (or 'Reviewee') */ public function i_allocate_submissions_in_workshop_as($workshopname, TableNode $table) { - $this->execute("behat_general::i_click_on_in_the", [$this->escape($workshopname), 'link', 'page', 'region']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname); $this->execute('behat_navigation::i_navigate_to_in_current_page_administration', get_string('allocate', 'workshop')); $rows = $table->getRows(); $reviewer = $participant = null; diff --git a/mod/workshop/tests/behat/behat_mod_workshop.php b/mod/workshop/tests/behat/behat_mod_workshop.php index 734bb8c49f3..51c1633d2b9 100644 --- a/mod/workshop/tests/behat/behat_mod_workshop.php +++ b/mod/workshop/tests/behat/behat_mod_workshop.php @@ -52,7 +52,7 @@ class behat_mod_workshop extends behat_base { $xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]"; $continue = $this->escape(get_string('continue')); - $this->execute("behat_general::i_click_on_in_the", [$this->escape($workshopname), 'link', 'page', 'region']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname); $this->execute('behat_general::i_click_on_in_the', array('a.action-icon', "css_element", $this->escape($xpath), "xpath_element") @@ -73,7 +73,7 @@ class behat_mod_workshop extends behat_base { $savechanges = $this->escape(get_string('savechanges')); $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ownsubmission ')]/descendant::*[@type='submit']"; - $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($workshopname), 'workshop activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname); $this->execute("behat_general::i_click_on", array($xpath, "xpath_element")); @@ -90,7 +90,7 @@ class behat_mod_workshop extends behat_base { * @param TableNode $table data to fill the submission form with, must contain 'Title' */ public function i_edit_assessment_form_in_workshop_as($workshopname, $table) { - $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($workshopname), 'workshop activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname); $this->execute('behat_navigation::i_navigate_to_in_current_page_administration', get_string('editassessmentform', 'workshop')); @@ -116,7 +116,7 @@ class behat_mod_workshop extends behat_base { $assess = $this->escape(get_string('assess', 'workshop')); $saveandclose = $this->escape(get_string('saveandclose', 'workshop')); - $this->execute("behat_navigation::i_am_on_page_instance", [$workshopname, 'workshop activity']); + $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname); $this->execute('behat_general::i_click_on_in_the', array($assess, "button", $xpath, "xpath_element")