mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
MDL-47588 behat: fix switching back to the main window in Chrome
This fix is mostly based on what Colin Chambers found out. This commit is a simplification of his work. The problem is that the Chrome / Selenium 2 integration cannot swich to a window with a blank name. The work-around applied here is, when we switch away from an unnamed window, we set a name on it. Then we can use that name to switch back.
This commit is contained in:
parent
b49de5d930
commit
a92105fd3f
1 changed files with 16 additions and 1 deletions
|
@ -49,6 +49,12 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException,
|
|||
*/
|
||||
class behat_general extends behat_base {
|
||||
|
||||
/**
|
||||
* @var string used by {@link switch_to_window()} and
|
||||
* {@link switch_to_the_main_window()} to work-around a Chrome browser issue.
|
||||
*/
|
||||
const MAIN_WINDOW_NAME = '__moodle_behat_main_window_name';
|
||||
|
||||
/**
|
||||
* Opens Moodle homepage.
|
||||
*
|
||||
|
@ -157,6 +163,15 @@ 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->getSession()->evaluateScript(
|
||||
'if (window.name == "") window.name = "' . self::MAIN_WINDOW_NAME . '"');
|
||||
|
||||
$this->getSession()->switchToWindow($windowname);
|
||||
}
|
||||
|
||||
|
@ -166,7 +181,7 @@ class behat_general extends behat_base {
|
|||
* @Given /^I switch to the main window$/
|
||||
*/
|
||||
public function switch_to_the_main_window() {
|
||||
$this->getSession()->switchToWindow();
|
||||
$this->getSession()->switchToWindow(self::MAIN_WINDOW_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue