mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 03:16:42 +02:00
MDL-82373 behat: Wait for alerts before accepting/dismissing them
This commit is contained in:
parent
8bba968f7b
commit
78ccdc9939
1 changed files with 19 additions and 2 deletions
|
@ -32,8 +32,11 @@ use Behat\Mink\Element\NodeElement;
|
|||
use Behat\Mink\Exception\DriverException;
|
||||
use Behat\Mink\Exception\ElementNotFoundException;
|
||||
use Behat\Mink\Exception\ExpectationException;
|
||||
use Facebook\WebDriver\Exception\NoSuchAlertException;
|
||||
use Facebook\WebDriver\Exception\NoSuchElementException;
|
||||
use Facebook\WebDriver\Exception\StaleElementReferenceException;
|
||||
use Facebook\WebDriver\WebDriverAlert;
|
||||
use Facebook\WebDriver\WebDriverExpectedCondition;
|
||||
|
||||
/**
|
||||
* Cross component steps definitions.
|
||||
|
@ -262,12 +265,25 @@ class behat_general extends behat_base {
|
|||
$this->getSession()->switchToWindow($names[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for an alert to be displayed.
|
||||
*
|
||||
* @return WebDriverAlert
|
||||
*/
|
||||
public function wait_for_alert(): WebDriverAlert {
|
||||
$webdriver = $this->getSession()->getDriver()->getWebdriver();
|
||||
$webdriver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
|
||||
|
||||
return $webdriver->switchTo()->alert();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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$/
|
||||
*/
|
||||
public function accept_currently_displayed_alert_dialog() {
|
||||
$this->getSession()->getDriver()->getWebDriver()->switchTo()->alert()->accept();
|
||||
$alert = $this->wait_for_alert();
|
||||
$alert->accept();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,7 +291,8 @@ class behat_general extends behat_base {
|
|||
* @Given /^I dismiss the currently displayed dialog$/
|
||||
*/
|
||||
public function dismiss_currently_displayed_alert_dialog() {
|
||||
$this->getSession()->getDriver()->getWebDriver()->switchTo()->alert()->dismiss();
|
||||
$alert = $this->wait_for_alert();
|
||||
$alert->dismiss();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue