Unexpected Alert Open Causes Error in Behat/Mink Test

241 views Asked by At

In my Behat test I click a link on the page that causes an alert to emerge, which I want to accept/press OK. I can't seem to deal with the alert because it causes an error that stops my tests:

 unexpected alert open: {Alert text : Are you sure you want to delete this item?}
   (Session info: chrome=88.0.4324.96): Are you sure you want to delete this item?
 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
 System info: host: 'b4201ea64648', ip: '172.20.0.4', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.39-linuxkit', java.version: '1.8.0_275'
 Driver info: driver.version: unknown (WebDriver\Exception\UnexpectedAlertOpen)

Feature file:

  @javascript
  Scenario: ...
    ...
    And I do something

Context file:

use PaulGibbs\WordpressBehatExtension\Context\RawWordpressContext;
class MyCuteContext extends RawWordpressContext {
    /**
     * @Given /^I do something$/
     */
    public function iDoSomething()
    {
        $page = $this->getSession()->getPage();

        ...

        $page->find(
            "css",
            "tbody > tr:nth-child(1)..."
        )->press();
    }
}

I don't seem to have access to a accept_alert function which I see is the advice when I search for this error. I've tried adding different variations of $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); which others online have advised with no luck. This line of code in particular gives me a grey squiggly in PHPStorm (underneath the getWebDriverSession portion)

"Potentially polymorphic call. The code may be inoperable depending on the actual class instance passed as the argument."

My mink settings in behat.yml are

    Behat\MinkExtension:
      base_url: http://nginx/
      # Use goutte (basic PHP browser, super fast) as the default driver.
      default_session: headless
      # Tag features/scenarios with @javascript to use the selenium2 driver.
      javascript_session: selenium2
      browser_name: chrome
      #browser_name: firefox
      selenium2:
        wd_host: http://browser:4444/wd/hub
        #capabilities: { "browserName": "chrome", "browser": "chrome", 'chrome': {'switches':['--no-sandbox', '--headless']}}
      sessions:
        headless:
          goutte:
            guzzle_parameters:
              verify: false

How can I accept/click OK on the alert that emerges?

0

There are 0 answers