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?
Mink is a php 5.3 library that you’ll use inside your test suites or project. Before you begin, ensure that you have at least PHP 5.3.1 installed. The recommended way to install Mink with all its dependencies is through Composer: For local installations of composer you must call it like this: $ php composer.phar require --dev behat/mink .
The simplest one is to use inheritance. Just extend your context from Behat\MinkExtension\Context\MinkContext instead of the base BehatContext. Note that you will also have to do this if you’ve already been using Behat in your project, but without Mink, and are now adding Mink to your testing:
In Mink, the entry point to the browser is called the session. Think about it as being your browser window (some drivers even let you switch tabs!). First, start your session (it’s like opening your browser tab). Nothing can be done with it before starting it. // Choose a Mink driver.
Mink is a PHP 5.3+ library that you’ll use inside your test and feature suites. Before you begin, ensure that you have at least PHP 5.3.1 installed. Mink integration into Behat happens thanks to MinkExtension. The extension takes care of all configuration and initialization of the Mink, leaving only the fun parts to you.
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]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With