MDL-70196 behat: Add a new step for navigating with the navbar.

- Part of: MDL-69588
A lot of tests work on the basis that you can follow the last item
of the breadcrumb nav bar. This is not the case. This step will first
check to see if the page is already the one requested. If it is then
nothing further needs to happen, otherwise we follow the link in the
navbar.
This commit is contained in:
Adrian Greeve
2021-08-23 17:46:38 +08:00
committed by Mathew May
parent c8422f4576
commit f28535082c
8 changed files with 30 additions and 14 deletions
+1 -1
View File
@@ -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'));
+16
View File
@@ -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);
}
}
}
+2 -2
View File
@@ -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();
+1 -1
View File
@@ -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');
+4 -4
View File
@@ -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);
}
@@ -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'));
@@ -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;
@@ -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")