-
-
Save blazarecki/2888851 to your computer and use it in GitHub Desktop.
<?php | |
namespace Widop\Mink\Extension; | |
/** | |
* Dictionary to manage popups. | |
* | |
* @author Benjamin Lazarecki <[email protected]> | |
*/ | |
trait PopupDictionary | |
{ | |
/** | |
* @when /^(?:|I )confirm the popup$/ | |
*/ | |
public function confirmPopup() | |
{ | |
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); | |
} | |
/** | |
* @when /^(?:|I )cancel the popup$/ | |
*/ | |
public function cancelPopup() | |
{ | |
$this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert(); | |
} | |
/** | |
* @When /^(?:|I )should see "([^"]*)" in popup$/ | |
* | |
* @param string $message The message. | |
* | |
* @return bool | |
*/ | |
public function assertPopupMessage($message) | |
{ | |
return $message == $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text(); | |
} | |
/** | |
* @When /^(?:|I )fill "([^"]*)" in popup$/ | |
* | |
* @param string $message The message. | |
*/ | |
public function setPopupText($message) | |
{ | |
$this->getSession()->getDriver()->getWebDriverSession()->postAlert_text($message); | |
} | |
} |
I have the same problem with Behat and Selenium (version 2.44).
My php function :
/**
* @When /^(?:|I )confirm the popup$/
*/
public function confirmPopup()
{
$wdSession = $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}
And the error when I launch the test :
[WebDriver\Exception\UnexpectedAlertOpen]
Modal dialog present: interface.delete.confirmation
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Thanks for your help
Thank! This gist was helpfull
Hi My function is :
**
* @when /^(?:|I )confirm the popup$/
*/
public function confirmPopup()
{
$wdSession = $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}
I'm not able to get ->getWebDriverSession , I am using Behat in PhpStorm, can you clarify if there is any missing code
/**
* @when /^I confirm popup$/
*/
public function iConfirmPopup()
{
$this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}
add this in featureContext.php file
and add "When I confirm popup " in your feature file
Now it works fine.
Here the stack-overflow question : http://stackoverflow.com/questions/18106137/how-to-handle-confirm-popup-with-phantomjs-behat-mink
tnx for your work. I only suggest to you to use the assert()
function instead of a simple return
This saved me a lot of time, thanks.