11<?php
22
3+ /**
4+ * @noinspection PhpUnhandledExceptionInspection
5+ * @noinspection PhpRedundantOptionalArgumentInspection
6+ */
7+
38namespace Behat \Mink \Tests \Driver \Js ;
49
510use Behat \Mink \Tests \Driver \TestCase ;
611
712final class WindowTest extends TestCase
813{
9- public function testWindow ()
14+ public function testWindow (): void
1015 {
1116 $ this ->getSession ()->visit ($ this ->pathTo ('/window.html ' ));
1217 $ session = $ this ->getSession ();
@@ -35,7 +40,7 @@ public function testWindow()
3540 $ this ->assertSame ('Main window div text ' , $ el ->getText ());
3641 }
3742
38- public function testGetWindowNames ()
43+ public function testGetWindowNames (): void
3944 {
4045 $ this ->getSession ()->visit ($ this ->pathTo ('/window.html ' ));
4146 $ session = $ this ->getSession ();
@@ -55,7 +60,7 @@ public function testGetWindowNames()
5560 $ this ->assertNotNull ($ windowNames [2 ]);
5661 }
5762
58- public function testResizeWindow ()
63+ public function testResizeWindow (): void
5964 {
6065 $ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
6166 $ session = $ this ->getSession ();
@@ -82,17 +87,33 @@ public function testResizeWindow()
8287 $ this ->assertTrue ($ session ->evaluateScript ($ jsWindowSizeScript ));
8388 }
8489
85- public function testWindowMaximize ()
90+ public function testWindowMaximize (): void
8691 {
8792 $ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
8893 $ session = $ this ->getSession ();
89-
90- $ session ->maximizeWindow ();
91- $ session ->wait (1000 , 'false ' );
92-
93- $ unusedWidth = $ session ->evaluateScript ('screen.availWidth - window.outerWidth ' );
94- $ unusedHeight = $ session ->evaluateScript ('screen.availHeight - window.outerHeight ' );
95- $ this ->assertLessThanOrEqual (0 , $ unusedWidth );
96- $ this ->assertLessThanOrEqual (0 , $ unusedHeight );
94+ $ popupName = 'testPopup ' ;
95+ $ createWindowJs = "window.open('about:blank', ' $ popupName', 'left=20,top=40,width=300,height=200') " ;
96+ $ getWindowPosJs = '
97+ return {
98+ top: window.screenY,
99+ left: window.screenX,
100+ right: window.screenX + window.innerWidth,
101+ bottom: window.screenX + window.innerHeight
102+ }
103+ ' ;
104+ $ session ->executeScript ($ createWindowJs );
105+ $ session ->switchToWindow ($ popupName );
106+ $ oldDim = (array )$ session ->evaluateScript ($ getWindowPosJs );
107+
108+ $ session ->maximizeWindow ($ popupName );
109+ $ newDim = (array )$ session ->evaluateScript ($ getWindowPosJs );
110+
111+ foreach (array_keys ($ oldDim ) as $ name ) {
112+ $ this ->assertNotEquals (
113+ $ oldDim [$ name ],
114+ $ newDim [$ name ],
115+ "The popup's $ name position should not be the same after maximizing "
116+ );
117+ }
97118 }
98119}
0 commit comments