From 26fef01b6b859fbf2185c4391c814546ef75e726 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Fri, 18 Nov 2016 07:34:31 +0800 Subject: [PATCH] MDL-56898 behat: Go to a non html page to avoid any unwanted ajax calls After scenario is finished, go to README.txt, so there is no JS/AJAX calls pending and site is ready for reset before next scenario --- lib/tests/behat/behat_hooks.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 71d824d832b..e1be9fdb586 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -411,6 +411,29 @@ class behat_hooks extends behat_base { $this->resize_window('medium'); } + /** + * Executed after scenario to go to a page where no JS is executed. + * This will ensure there are no unwanted ajax calls from browser and + * site can be reset safely. + * + * @param AfterScenarioScope $scope scope passed by event fired after scenario. + * @AfterScenario + */ + public function after_scenario(AfterScenarioScope $scope) { + try { + $this->wait_for_pending_js(); + $this->getSession()->visit($this->locate_path('/README.txt')); + $this->getSession()->reset(); + } catch (DriverException $e) { + // Try restart session, if DriverException caught. + try { + $this->getSession()->restart(); + } catch (DriverException $e) { + // Do nothing, as this will be caught while starting session in before_scenario. + } + } + } + /** * Wait for JS to complete before beginning interacting with the DOM. *