MDL-68826 behat: new step I close all opened windows

This commit is contained in:
Ferran Recio 2020-05-26 18:48:08 +02:00
parent 2e324c14bf
commit 709cab79ed

View file

@ -243,6 +243,30 @@ class behat_general extends behat_base {
$this->getSession()->switchToWindow(self::MAIN_WINDOW_NAME);
}
/**
* Closes all extra windows opened during the navigation.
*
* This assumes all popups are opened by the main tab and you will now get back.
*
* @Given /^I close all opened windows$/
* @throws DriverException If there aren't exactly 1 tabs open when finish or no javascript running
*/
public function i_close_all_opened_windows() {
if (!$this->running_javascript()) {
throw new DriverException('Closing windows steps require javascript');
}
$names = $this->getSession()->getWindowNames();
for ($index = 1; $index < count($names); $index ++) {
$this->getSession()->switchToWindow($names[$index]);
$this->getSession()->executeScript("window.open('', '_self').close();");
}
$names = $this->getSession()->getWindowNames();
if (count($names) !== 1) {
throw new DriverException('Expected to see 1 tabs open, not ' . count($names));
}
$this->getSession()->switchToWindow($names[0]);
}
/**
* Accepts the currently displayed alert dialog. This step does not work in all the browsers, consider it experimental.
* @Given /^I accept the currently displayed dialog$/