Skip to content

Instantly share code, notes, and snippets.

@b0n
Forked from acfreitas/Popup.php
Created September 13, 2016 03:02
Show Gist options
  • Save b0n/e8ef5cd4e9803eec0d82e1e7a4422caa to your computer and use it in GitHub Desktop.
Save b0n/e8ef5cd4e9803eec0d82e1e7a4422caa to your computer and use it in GitHub Desktop.
Working with popup and Behat/Mink Behat3
<?php
use Behat\MinkExtension\Context\RawMinkContext;
/**
* Add Popup in Context
*/
class Popup extends RawMinkContext
{
/**
* @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.
*/
public function assertPopupMessage($message)
{
$alertText = $this->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->getSession()->getDriver()->getWebDriverSession()->postAlert_text($message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment