From 29bcee1db5f4da92431b07eb82a488e3ea755179 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 15 Jan 2019 15:12:06 +0000 Subject: [PATCH] MDL-63977 Behat: Move app startup to before-scenario hook --- behat_app.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/behat_app.php b/behat_app.php index a211dcef9..d307f2027 100644 --- a/behat_app.php +++ b/behat_app.php @@ -42,6 +42,9 @@ class behat_app extends behat_base { /** @var stdClass Object with data about launched Ionic instance (if any) */ protected static $ionicrunning = null; + /** @var string URL for running Ionic server */ + protected $ionicurl = ''; + /** * Checks if the current OS is Windows, from the point of view of task-executing-and-killing. * @@ -51,6 +54,17 @@ class behat_app extends behat_base { return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; } + /** + * Called from behat_hooks when a new scenario starts, if it has the app tag. + * + * This updates Moodle configuration and starts Ionic running, if it isn't already. + */ + public function start_scenario() { + $this->check_behat_setup(); + $this->fix_moodle_setup(); + $this->ionicurl = $this->start_or_reuse_ionic(); +} + /** * Opens the Moodle app in the browser. * @@ -62,19 +76,17 @@ class behat_app extends behat_base { * @throws ExpectationException Problem with resizing window */ public function i_enter_the_app() { + // Check the app tag was set. + if (!$this->has_tag('app')) { + throw new DriverException('Requires @app tag on scenario or feature.'); + } + // Restart the browser and set its size. $this->getSession()->restart(); $this->resize_window('360x720', true); - // Prepare setup. - $this->check_behat_setup(); - $this->fix_moodle_setup(); - - // Start Ionic server (or use existing one). - $url = $this->start_or_reuse_ionic(); - // Go to page and prepare browser for app. - $this->prepare_browser($url); + $this->prepare_browser($this->ionicurl); } /** @@ -85,11 +97,6 @@ class behat_app extends behat_base { protected function check_behat_setup() { global $CFG; - // Check the app tag was set. - if (!$this->has_tag('app')) { - throw new DriverException('Requires @app tag on scenario or feature.'); - } - // Check JavaScript is enabled. if (!$this->running_javascript()) { throw new DriverException('The app requires JavaScript.');