MDL-66979 behat: Fix window switching
Normalise switching of window contexts by setting the main window name to a null. Where the window has no name (null/empty), then the root context is selected.
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user