如何确认Behat弹出窗口的确定?

I want to confirm the popup when it appears. Here is the feature file:

And I wait 10 seconds
Then I confirm the popup

And The FeatureContext file:

<?php

    use Behat\Behat\Context\Context;
    use Behat\Behat\Context\SnippetAcceptingContext;
    use Behat\Gherkin\Node\PyStringNode;
    use Behat\Gherkin\Node\TableNode;
    use Behat\MinkExtension\Context\MinkContext;
    use Behat\Mink\Driver\Selenium2Driver;

    class FeatureContext extends MinkContext { 
    /**
     * @when /^(?:|I )confirm the popup$/
     */
        public function confirmPopup()   {
            $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
        }
    }

But it doesn't work. It shows the following error: Error Image

Assuming that you are using Behat 3, you can add this step in any context that extends Page object.

public function iConfirmThePopup()
{
    $this->getDriver()->getWebDriverSession()->accept_alert();
}

If you have any delay in the pop-up appearing you can add a sleep(1); in the method before calling the accept alert method.

This code would work for alert type, if the pop-p is not an alert then you need to use a regular click on the ok/confirm button.

You can use:

/**
 * @when /^(?:|I )confirm the popup$/
 */
public function confirmPopup()
{
    $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}

I found this file, very handy:

https://gist.github.com/blazarecki/2888851

This file contain how to handle them all popups