diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 6c5efe43029..645a647d90a 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -59,6 +59,11 @@ class behat_hooks extends behat_base { */ protected static $lastbrowsersessionstart = 0; + /** + * @var For actions that should only run once. + */ + protected static $initprocessesfinished = false; + /** * Gives access to moodle codebase, ensures all is ready and sets up the test lock. * @@ -161,6 +166,15 @@ class behat_hooks extends behat_base { // Start always in the the homepage. $this->getSession()->visit($this->locate_path('/')); + // Checking that the root path is a Moodle test site. + if (self::is_first_scenario()) { + $notestsiteexception = new Exception('The base URL (' . $CFG->wwwroot . ') is not a behat test site, ' . + 'ensure you started the built-in web server in the correct directory'); + $this->find("xpath", "//head/child::title[normalize-space(.)='Acceptance test site']", $notestsiteexception); + + self::$initprocessesfinished = true; + } + // Closing JS dialogs if present. Otherwise they would block this scenario execution. if ($this->running_javascript()) { try { @@ -335,4 +349,12 @@ class behat_hooks extends behat_base { return preg_replace("/(\n)+/s", "\n", $notags); } + /** + * Returns whether the first scenario of the suite is running + * + * @return bool + */ + protected static function is_first_scenario() { + return !(self::$initprocessesfinished); + } }