From 9136cf7ce9f496d9c2b7001f213071ecd584ed31 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 adc150d3b08eb..975d16f7187b2 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -368,6 +368,29 @@ function($errno, $errstr, $errfile, $errline) { $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. *