Skip to content

Instantly share code, notes, and snippets.

@acfreitas
Forked from blazarecki/PopupDictionary.php
Last active January 10, 2018 11:18
Show Gist options
  • Save acfreitas/4d0778e8690e5d3a1de7 to your computer and use it in GitHub Desktop.
Save acfreitas/4d0778e8690e5d3a1de7 to your computer and use it in GitHub Desktop.
Working with popup and Behat/Mink
<?php
use Behat\Behat\Context\BehatContext;
/**
* Add Popup in Context
*/
class Popup extends BehatContext
{
/**
* @when /^(?:|I )confirm the popup$/
*/
public function confirmPopup()
{
$this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}
/**
* @when /^(?:|I )cancel the popup$/
*/
public function cancelPopup()
{
$this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->dismiss_alert();
}
/**
* @When /^(?:|I )should see "([^"]*)" in popup$/
*
* @param string $message The message.
*/
public function assertPopupMessage($message)
{
$alertText = $this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->getAlert_text();
if ($alertText !== $message){
throw new Exception("Modal dialog present: $alertText, when expected was $message");
}
}
/**
* @When /^(?:|I )fill "([^"]*)" in popup$/
*
* @param string $message The message.
*/
public function setPopupText($message)
{
$this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->postAlert_text($message);
}
}
@b0n
Copy link

b0n commented Sep 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment