MDL-38958 behat: Step definitions to interact with popup windows

This commit is contained in:
David Monllao
2013-04-11 13:58:11 +08:00
parent 336b5b5914
commit 1303eb290f
2 changed files with 28 additions and 4 deletions
+19
View File
@@ -63,6 +63,25 @@ class behat_general extends behat_base {
$this->getSession()->reload();
}
/**
* Switches to the specified window. Useful when interacting with popup windows.
*
* @Given /^I switch to "(?P<window_name_string>(?:[^"]|\\")*)" window$/
* @param string $windowname
*/
public function switch_to_window($windowname) {
$this->getSession()->switchToWindow($windowname);
}
/**
* Switches to the main Moodle window. Useful when you finish interacting with popup windows.
*
* @Given /^I switch to the main window$/
*/
public function switch_to_the_main_window() {
$this->getSession()->switchToWindow();
}
/**
* Clicks link with specified id|title|alt|text.
*
+9 -4
View File
@@ -29,9 +29,10 @@
require_once(__DIR__ . '/../../behat/behat_base.php');
use Behat\Behat\Event\SuiteEvent as SuiteEvent;
use Behat\Behat\Event\ScenarioEvent as ScenarioEvent;
use Behat\Behat\Event\StepEvent as StepEvent;
use Behat\Behat\Event\SuiteEvent as SuiteEvent,
Behat\Behat\Event\ScenarioEvent as ScenarioEvent,
Behat\Behat\Event\StepEvent as StepEvent,
WebDriver\Exception\NoSuchWindow as NoSuchWindow;
/**
* Hooks to the behat process.
@@ -170,7 +171,11 @@ class behat_hooks extends behat_base {
}
// Wait until the page is ready.
$this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")');
try {
$this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")');
} catch (NoSuchWindow $e) {
// If we were interacting with a popup window it will not exists after closing it.
}
}
}