2015-08-18 00:00:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Behat\Mink\Tests\Driver\Js;
|
|
|
|
|
|
|
|
use Behat\Mink\Tests\Driver\TestCase;
|
|
|
|
|
|
|
|
class WindowTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testWindow()
|
|
|
|
{
|
|
|
|
$this->getSession()->visit($this->pathTo('/window.html'));
|
|
|
|
$session = $this->getSession();
|
2015-10-08 18:40:12 +00:00
|
|
|
$page = $session->getPage();
|
2015-08-18 00:00:26 +00:00
|
|
|
$webAssert = $this->getAssertSession();
|
|
|
|
|
|
|
|
$page->clickLink('Popup #1');
|
|
|
|
$session->switchToWindow(null);
|
|
|
|
|
|
|
|
$page->clickLink('Popup #2');
|
|
|
|
$session->switchToWindow(null);
|
|
|
|
|
|
|
|
$el = $webAssert->elementExists('css', '#text');
|
|
|
|
$this->assertSame('Main window div text', $el->getText());
|
|
|
|
|
|
|
|
$session->switchToWindow('popup_1');
|
|
|
|
$el = $webAssert->elementExists('css', '#text');
|
|
|
|
$this->assertSame('Popup#1 div text', $el->getText());
|
|
|
|
|
|
|
|
$session->switchToWindow('popup_2');
|
|
|
|
$el = $webAssert->elementExists('css', '#text');
|
|
|
|
$this->assertSame('Popup#2 div text', $el->getText());
|
|
|
|
|
|
|
|
$session->switchToWindow(null);
|
|
|
|
$el = $webAssert->elementExists('css', '#text');
|
|
|
|
$this->assertSame('Main window div text', $el->getText());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetWindowNames()
|
|
|
|
{
|
|
|
|
$this->getSession()->visit($this->pathTo('/window.html'));
|
|
|
|
$session = $this->getSession();
|
2015-10-08 18:40:12 +00:00
|
|
|
$page = $session->getPage();
|
2015-08-18 00:00:26 +00:00
|
|
|
|
|
|
|
$windowName = $this->getSession()->getWindowName();
|
|
|
|
|
|
|
|
$this->assertNotNull($windowName);
|
|
|
|
|
|
|
|
$page->clickLink('Popup #1');
|
|
|
|
$page->clickLink('Popup #2');
|
|
|
|
|
|
|
|
$windowNames = $this->getSession()->getWindowNames();
|
|
|
|
|
|
|
|
$this->assertNotNull($windowNames[0]);
|
|
|
|
$this->assertNotNull($windowNames[1]);
|
|
|
|
$this->assertNotNull($windowNames[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testResizeWindow()
|
|
|
|
{
|
|
|
|
$this->getSession()->visit($this->pathTo('/index.html'));
|
|
|
|
$session = $this->getSession();
|
|
|
|
|
|
|
|
$session->resizeWindow(400, 300);
|
|
|
|
$session->wait(1000, 'false');
|
|
|
|
|
2015-10-08 18:40:12 +00:00
|
|
|
$script = 'return Math.abs(window.outerHeight - 300) <= 100 && Math.abs(window.outerWidth - 400) <= 100;';
|
2015-08-18 00:00:26 +00:00
|
|
|
|
|
|
|
$this->assertTrue($session->evaluateScript($script));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWindowMaximize()
|
|
|
|
{
|
|
|
|
$this->getSession()->visit($this->pathTo('/index.html'));
|
|
|
|
$session = $this->getSession();
|
|
|
|
|
|
|
|
$session->maximizeWindow();
|
|
|
|
$session->wait(1000, 'false');
|
|
|
|
|
2015-10-08 18:40:12 +00:00
|
|
|
$script = 'return Math.abs(screen.availHeight - window.outerHeight) <= 100;';
|
2015-08-18 00:00:26 +00:00
|
|
|
|
|
|
|
$this->assertTrue($session->evaluateScript($script));
|
|
|
|
}
|
|
|
|
}
|