Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-39686_25' of git://github.com/dmonllao/moodle into …

…MOODLE_25_STABLE
  • Loading branch information...
commit a665577b37edf1e800f2a2015a049e1f5f8dd41f 2 parents f32e55c + c0b5915
@damyon damyon authored
Showing with 27 additions and 0 deletions.
  1. +7 −0 config-dist.php
  2. +20 −0 lib/tests/behat/behat_hooks.php
View
7 config-dist.php
@@ -587,6 +587,13 @@
// 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
View
20 lib/tests/behat/behat_hooks.php
@@ -55,6 +55,11 @@
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.
*
* Includes config.php to use moodle codebase with $CFG->behat_*
@@ -102,6 +107,12 @@ public static function before_suite($event) {
}
// 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 @@ public function before_scenario($event) {
$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('/'));
Please sign in to comment.
Something went wrong with that request. Please try again.