Domanda

I am running through an internal site with Behat and for the most part it is going really well. But the problem is that on certain parts of the site we have popup windows that come up to complete an action. In this case we hit a "Withdraw" button and a popup comes up to have you select a reason and save it.

In an ideal world, and if I had actually designed this app, the site wouldn't be using any popup windows. But I am the new guy who is supposed to implement automated functional tests (and I am learning how to do that from the ground up). So I don't really have any say over the site design at this point (though I will push for a lot of changes as time goes by).

I am running Behat with Mink and the Selenium 2 driver on an Ubuntu 12.10 system (will eventually have to run some tests on a Windows environment for testing in IE). I am also using PhantomJS for some of the tests I have setup.

Anyway, does Behat/Mink support working with popup windows somehow through the Selenium 2 driver (or through PhantomJS)? I am early in all of this automation setup and really I am just experimenting with tools. If there is a better tool that can handle this then please let me know.

My primary question is how do I get Behat/Mink to work with the popup window, check a box, fill in a field, and click the save button? I know how to do everything except get it to interact directly with the newly popped up window. Any ideas/suggestions would be welcome.

Thanks!

È stato utile?

Soluzione

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

Altri suggerimenti

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');
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top