phpbrowserautomationbehatmink

How to handle browser window or tab using Behat and Mink PHP


I have test that click on link and then new browser window open and in new browser window I need to check some elements are present. How to switch to new Browser window that was opened using BEHAT/MINK?


Solution

  • You can use switchToWindow($windowName) method.

    $this->getSession()->switchToWindow($windowName);
    

    Method declaration is here

    You can get all windows from current session and then switch to the second one for example

    $windowNames = $this->getSession()->getWindowNames();
    if(count($windowNames) > 1) {
        $this->getSession()->switchToWindow($windowNames[1]);
    }