How do I interact with a popup window with Mink, Selenium 2, and Behat? How do I interact with a popup window with Mink, Selenium 2, and Behat? selenium selenium

How do I interact with a popup window with Mink, Selenium 2, and Behat?


So it turns out that Mink includes some window switching features, but no way to identify said windows. So I wrote two functions getWindowName() and getWindowNames() that identify the current window and all open windows respectively. I committed these changes to the project in GitHub it seems that my fixes will get implemented soon into the code base.

But with these changes I am able to switch windows no problem.

Link: https://github.com/Behat/Mink/pull/341


By setting the focus of the window we can also name these windows so we can access them again in the future.

Using this method we can easily switch between popup windows and continue testing...

    /** * @Then I switch to popup :name * * @param $name */public function iSwitchToPopup($name){    $this->iSetMainWindowName();    $this->getSession()->switchToWindow($name);}/** * @Then I set main window name */public function iSetMainWindowName(){    $window_name = 'main_window';    $script = 'window.name = "' . $window_name . '"';    $this->getSession()->executeScript($script);}/** * @Then I switch back to main window */public function iSwitchBackToMainWindow(){    $this->getSession()->switchToWindow('main_window');}