From 886b44bbd39534344bd0454932ff6ea7fab9107e Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 15 May 2013 16:12:15 +0800 Subject: [PATCH 1/2] MDL-39686 behat: Adding into to config-dist.php --- config-dist.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config-dist.php b/config-dist.php index 378d3416435..e24e8431486 100644 --- a/config-dist.php +++ b/config-dist.php @@ -587,6 +587,13 @@ $CFG->admin = 'admin'; // Example: // $CFG->behat_switchcompletely = true; // +// You can force the browser session (not user's sessions) to restart after N seconds. This could +// be useful if you are using a cloud-based service with time restrictions in the browser side. +// Setting this value the browser session that Behat is using will be restarted. Set the time in +// seconds. Is not recommended to use this setting if you don't explicitly need it. +// Example: +// $CFG->behat_restart_browser_after = 7200; // Restarts the browser session after 2 hours +// //========================================================================= // ALL DONE! To continue installation, visit your main page with a browser From 41eb672ba442bfd10dd691b3300c73db7bdb8232 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 15 May 2013 16:15:47 +0800 Subject: [PATCH 2/2] MDL-39686 behat: Add option to restart the browser --- lib/tests/behat/behat_hooks.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 5cc8112cb65..41d6b77fe10 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -54,6 +54,11 @@ use Behat\Behat\Event\SuiteEvent as SuiteEvent, */ class behat_hooks extends behat_base { + /** + * @var Last browser session start time. + */ + protected static $lastbrowsersessionstart = 0; + /** * Gives access to moodle codebase, ensures all is ready and sets up the test lock. * @@ -102,6 +107,12 @@ class behat_hooks extends behat_base { } // Avoid parallel tests execution, it continues when the previous lock is released. test_lock::acquire('behat'); + + // Store the browser reset time if reset after N seconds is specified in config.php. + if (!empty($CFG->behat_restart_browser_after)) { + // Store the initial browser session opening. + self::$lastbrowsersessionstart = time(); + } } /** @@ -138,6 +149,15 @@ class behat_hooks extends behat_base { $user = $DB->get_record('user', array('username' => 'admin')); session_set_user($user); + // Reset the browser if specified in config.php. + if (!empty($CFG->behat_restart_browser_after) && $this->running_javascript()) { + $now = time(); + if (self::$lastbrowsersessionstart + $CFG->behat_restart_browser_after < $now) { + $this->getSession()->restart(); + self::$lastbrowsersessionstart = $now; + } + } + // Start always in the the homepage. $this->getSession()->visit($this->locate_path('/'));