diff --git a/auth/email/tests/behat/behat_auth_email.php b/auth/email/tests/behat/behat_auth_email.php index b3fe2fbbca1..83924f7029b 100644 --- a/auth/email/tests/behat/behat_auth_email.php +++ b/auth/email/tests/behat/behat_auth_email.php @@ -49,6 +49,6 @@ class behat_auth_email extends behat_base { $confirmationpath = $confirmationurl->out_as_local_url(false); $url = $confirmationpath . '?' . 'data='. $secret .'/'. $username; - $this->getSession()->visit($this->locate_path($url)); + $this->execute('behat_general::i_visit', [$url]); } } diff --git a/auth/tests/behat/behat_auth.php b/auth/tests/behat/behat_auth.php index 7df38c70fd8..6103ace6b55 100644 --- a/auth/tests/behat/behat_auth.php +++ b/auth/tests/behat/behat_auth.php @@ -53,7 +53,7 @@ class behat_auth extends behat_base { } // Visit login page. - $this->getSession()->visit($this->locate_path($loginurl->out_as_local_url())); + $this->execute('behat_general::i_visit', [$loginurl]); // Enter username and password. $this->execute('behat_forms::i_set_the_field_to', array('Username', $this->escape($username))); diff --git a/backup/util/ui/tests/behat/behat_backup.php b/backup/util/ui/tests/behat/behat_backup.php index a5ead378370..fe5f57544be 100644 --- a/backup/util/ui/tests/behat/behat_backup.php +++ b/backup/util/ui/tests/behat/behat_backup.php @@ -56,7 +56,7 @@ class behat_backup extends behat_base { // table elements are used, and we need to catch exceptions contantly. // Go to homepage. - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); $this->execute("behat_general::wait_until_the_page_is_ready"); // Click the course link. @@ -98,7 +98,7 @@ class behat_backup extends behat_base { // table elements are used, and we need to catch exceptions contantly. // Go to homepage. - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); // Click the course link. $this->execute("behat_general::click_link", $backupcourse); @@ -134,7 +134,7 @@ class behat_backup extends behat_base { // table elements are used, and we need to catch exceptions contantly. // Go to homepage. - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); $this->execute("behat_general::wait_until_the_page_is_ready"); // Click the course link. diff --git a/calendar/tests/behat/behat_calendar.php b/calendar/tests/behat/behat_calendar.php index 0bd835cc666..f15d85bb32c 100644 --- a/calendar/tests/behat/behat_calendar.php +++ b/calendar/tests/behat/behat_calendar.php @@ -121,7 +121,7 @@ class behat_calendar extends behat_base { */ public function i_view_the_calendar_for($month, $year) { $time = make_timestamp($year, $month, 1); - $this->getSession()->visit($this->locate_path('/calendar/view.php?view=month&course=1&time='.$time)); + $this->execute('behat_general::i_visit', ['/calendar/view.php?view=month&course=1&time='.$time]); } } diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 3ed1a16a10d..351887a9ef2 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -74,7 +74,7 @@ class behat_general extends behat_base { * @Given /^I am on homepage$/ */ public function i_am_on_homepage() { - $this->getSession()->visit($this->locate_path('/')); + $this->execute('behat_general::i_visit', ['/']); } /** @@ -83,7 +83,7 @@ class behat_general extends behat_base { * @Given /^I am on site homepage$/ */ public function i_am_on_site_homepage() { - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); } /** @@ -92,7 +92,7 @@ class behat_general extends behat_base { * @Given /^I am on course index$/ */ public function i_am_on_course_index() { - $this->getSession()->visit($this->locate_path('/course/index.php')); + $this->execute('behat_general::i_visit', ['/course/index.php']); } /** @@ -1005,7 +1005,7 @@ EOF; * @Given /^I trigger cron$/ */ public function i_trigger_cron() { - $this->getSession()->visit($this->locate_path('/admin/cron.php')); + $this->execute('behat_general::i_visit', ['/admin/cron.php']); } /** @@ -1778,4 +1778,16 @@ EOF; $value = ($shift == ' shift') ? [\WebDriver\Key::SHIFT . \WebDriver\Key::TAB] : [\WebDriver\Key::TAB]; $this->getSession()->getDriver()->getWebDriverSession()->activeElement()->postValue(['value' => $value]); } + + /** + * Visit a local URL relative to the behat root. + * + * @When I visit :localurl + * + * @param string|moodle_url $localurl The URL relative to the behat_wwwroot to visit. + */ + public function i_visit($localurl) { + $localurl = new moodle_url($localurl); + $this->getSession()->visit($this->locate_path($localurl->out_as_local_url(false))); + } } diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 5a47176811d..7491a6a30b0 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -486,7 +486,7 @@ EOF; // Again, this would be better in the BeforeSuite hook, but that does not have access to the selectors in // order to perform the necessary searches. $session = $this->getSession(); - $session->visit($this->locate_path('/')); + $this->execute('behat_general::i_visit', ['/']); // Checking that the root path is a Moodle test site. if (self::is_first_scenario()) { diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 0ec0d98294f..b9b1a3743b4 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -567,7 +567,7 @@ class behat_navigation extends behat_base { } } - $this->getSession()->visit($this->locate_path($url->out_as_local_url())); + $this->execute('behat_general::i_visit', [$url]); } // Restore global user variable. @@ -590,8 +590,7 @@ class behat_navigation extends behat_base { * @throws Exception if the specified page cannot be determined. */ public function i_am_on_page(string $page) { - $this->getSession()->visit($this->locate_path( - $this->resolve_page_helper($page)->out_as_local_url())); + $this->execute('behat_general::i_visit', [$this->resolve_page_helper($page)]); } /** @@ -670,8 +669,7 @@ class behat_navigation extends behat_base { * @throws Exception if the specified page cannot be determined. */ public function i_am_on_page_instance(string $identifier, string $type) { - $this->getSession()->visit($this->locate_path( - $this->resolve_page_instance_helper($identifier, $type)->out_as_local_url())); + $this->execute('behat_general::i_visit', [$this->resolve_page_instance_helper($identifier, $type)]); } /** @@ -776,7 +774,7 @@ class behat_navigation extends behat_base { global $DB; $course = $DB->get_record("course", array("fullname" => $coursefullname), 'id', MUST_EXIST); $url = new moodle_url('/course/view.php', ['id' => $course->id]); - $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute('behat_general::i_visit', [$url]); } /** @@ -797,13 +795,13 @@ class behat_navigation extends behat_base { // Javascript is running so it is possible to grab the session ket and jump straight to editing mode. $url->param('edit', 1); $url->param('sesskey', $sesskey); - $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute('behat_general::i_visit', [$url]); return; } // Visit the course page. - $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute('behat_general::i_visit', [$url]); try { $this->execute("behat_forms::press_button", get_string('turneditingon'));