From 675e9810047f0fa0b0c4f8f6136d02562975074c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 15 Jun 2020 10:37:52 +0800 Subject: [PATCH 1/3] MDL-69072 behat: Relaunch browser session between scenarios --- lib/tests/behat/behat_hooks.php | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 115765a97f0..5ee4caf1b14 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -576,25 +576,13 @@ class behat_hooks extends behat_base { } /** - * Executed after scenario having switch window to restart session. - * This is needed to close all extra browser windows and starting - * one browser window. + * Reset the session between each scenario. * * @param AfterScenarioScope $scope scope passed by event fired after scenario. - * @AfterScenario @_switch_window + * @AfterScenario */ - public function after_scenario_switchwindow(AfterScenarioScope $scope) { - for ($count = 0; $count < behat_base::get_extended_timeout(); $count++) { - try { - $this->getSession()->restart(); - break; - } catch (DriverException $e) { - // Wait for timeout and try again. - sleep(self::get_timeout()); - } - } - // If session is not restarted above then it will try to start session before next scenario - // and if that fails then exception will be thrown. + public function reset_webdriver_between_scenarios(AfterScenarioScope $scope) { + $this->getSession()->stop(); } /** From 868a1c377d1fd465457edb77c3631c529aab2735 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 16 Jun 2020 08:23:33 +0800 Subject: [PATCH 2/3] MDL-69072 mod_scorm: Stop mink reset after tests This is now done for all scenarios. It is no longer necessary to do so specifically for mod_scorm. --- mod/scorm/tests/behat/behat_mod_scorm.php | 54 ----------------------- 1 file changed, 54 deletions(-) delete mode 100644 mod/scorm/tests/behat/behat_mod_scorm.php diff --git a/mod/scorm/tests/behat/behat_mod_scorm.php b/mod/scorm/tests/behat/behat_mod_scorm.php deleted file mode 100644 index ed7e16f1821..00000000000 --- a/mod/scorm/tests/behat/behat_mod_scorm.php +++ /dev/null @@ -1,54 +0,0 @@ -. - -/** - * Steps definitions related to the SCORM activity module. - * - * @package mod_scorm - * @category test - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. - -require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); - -use Behat\Behat\Hook\Scope\AfterScenarioScope; - -/** - * Steps definitions related to the SCORM activity module. - * - * @package mod_scorm - * @category test - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class behat_mod_scorm extends behat_base { - - /** - * Restart the Seleium Session after each mod_scorm Scenario. - * - * This prevents issues with the scorm player's onbeforeunload event, and cached SCORM content being served to the - * browser in subsequent tests. - * - * @AfterScenario @mod_scorm - * @param AfterScenarioScope $scope The scenario scope - */ - public function reset_after_scorm(AfterScenarioScope $scope) { - $this->getSession()->stop(); - } -} From aacfff0bc837853a7cefdf4d33b2b996c614be9f Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 16 Jun 2020 08:24:52 +0800 Subject: [PATCH 3/3] MDL-69072 behat: Remove restart_browser_after feature This is no longer required as the Mink session is restarted after every test regardless. --- config-dist.php | 7 ------- lib/tests/behat/behat_hooks.php | 20 -------------------- lib/upgrade.txt | 4 ++++ 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/config-dist.php b/config-dist.php index 995e0df8b0c..ecd56b6b6fa 100644 --- a/config-dist.php +++ b/config-dist.php @@ -898,13 +898,6 @@ $CFG->admin = 'admin'; // ), // ); // -// 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 this page's extra Moodle settings are compared against a white list of allowed settings // (the basic and behat_* ones) to avoid problems with production environments. This setting can be // used to expand the default white list with an array of extra settings. diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 5ee4caf1b14..2ba7b37fda3 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -63,11 +63,6 @@ use Behat\Testwork\Hook\Scope\BeforeSuiteScope, */ class behat_hooks extends behat_base { - /** - * @var Last browser session start time. - */ - protected static $lastbrowsersessionstart = 0; - /** * @var For actions that should only run once. */ @@ -196,12 +191,6 @@ 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(); - } - if (!empty($CFG->behat_faildump_path) && !is_writable($CFG->behat_faildump_path)) { throw new behat_stop_exception('You set $CFG->behat_faildump_path to a non-writable directory'); } @@ -381,15 +370,6 @@ class behat_hooks extends behat_base { $user = $DB->get_record('user', array('username' => 'admin')); \core\session\manager::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) { - $session->restart(); - self::$lastbrowsersessionstart = $now; - } - } - // Set the theme if not default. if ($suitename !== "default") { set_config('theme', $suitename); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 4e79b930750..523e395d28f 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. +=== 3.9.1 === +* The `$CFG->behat_retart_browser_after` configuration setting has been removed. + The browser session is now restarted between all tests. + === 3.9 === * Following function has been deprecated, please use \core\task\manager::run_from_cli(). - cron_run_single_task()