diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 2b92271a686..ed2f2953a06 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -67,9 +67,11 @@ class behat_forms extends behat_base { // Ensures the button is present, before pressing. $buttonnode = $this->find_button($button); $buttonnode->press(); + $this->wait_for_pending_js(); + $this->look_for_exceptions(); // Switch to main window. - $this->getSession()->switchToWindow(behat_general::MAIN_WINDOW_NAME); + $this->execute('behat_general::switch_to_the_main_window'); } /** diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index a108c40e290..0f555d56b57 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -203,13 +203,11 @@ class behat_general extends behat_base { * @param string $windowname */ public function switch_to_window($windowname) { - // In Behat, some browsers (e.g. Chrome) are unable to switch to a - // window without a name, and by default the main browser window does - // not have a name. To work-around this, when we switch away from an - // unnamed window (presumably the main window) to some other named - // window, then we first set the main window name to a conventional - // value that we can later use this name to switch back. - $this->execute_script('if (window.name == "") window.name = "' . self::MAIN_WINDOW_NAME . '"'); + if ($windowname === self::MAIN_WINDOW_NAME) { + // When switching to the main window normalise the window name to null. + // This is normalised further in the Mink driver to the root window ID. + $windowname = null; + } $this->getSession()->switchToWindow($windowname); } @@ -220,7 +218,7 @@ class behat_general extends behat_base { * @Given /^I switch to the main window$/ */ public function switch_to_the_main_window() { - $this->getSession()->switchToWindow(self::MAIN_WINDOW_NAME); + $this->switch_to_window(self::MAIN_WINDOW_NAME); } /**