0
我正在Behat上运行一个测试,点击一个打开另一个页面的按钮,我想与该页面进行交互(一开始为屏幕截图)。behat/mink打开窗口并截取它的屏幕截图
我想是这样的
public function iTakeAScreenshotOfTheNewWindow($filename)
{
$windowNames = $this->getSession()->getWindowNames();
$driver = $this->getSession()->getDriver();
if(count($windowNames) == 1) {
throw new \Behat\Mink\Exception\ExpectationException("No extra window found", $driver);
}
$lastWindow = array_pop($windowNames);
$driver->switchToWindow($lastWindow);
if (!$driver instanceof PhantomJSDriver) {
throw new UnsupportedDriverActionException('This step is only supported by the PhantomJS driver', $driver);
}
$screenshot = $driver->getScreenshot();
file_put_contents($filename, $screenshot);
$this->getSession()->switchToWindow(); //back to main window
}
但我得到的错误
Could not find window handle by a given window name: 1 (Behat\Mink\Exception\DriverException)
之前,我点击按钮(并打开新的窗口),$ windowNames的vardump显示:
array(1) {
[0]=>
string(1) "0"
}
窗口打开后:
array(2) {
[0]=>
string(1) "0"
[1]=>
string(1) "1"
}
如何更改窗口?
感谢
的方法不存在:调用未定义的方法,尊巴舞\ Mink \ Driver \ PhantomJSDriver :: getWebDriverSession() – Jon
将此添加到扩展MinkContext的类中。 – lauda
这就是我添加它的地方:)但是我收到了错误信息 – Jon