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 ();
@@ -47,7 +52,7 @@ public function testWindowName(): void
4752 $ this ->assertContains ($ windowName , $ windowNames , 'The current window name should be one of the available window names. ' );
4853 }
4954
50- public function testGetWindowNames ()
55+ public function testGetWindowNames (): void
5156 {
5257 $ this ->getSession ()->visit ($ this ->pathTo ('/window.html ' ));
5358 $ session = $ this ->getSession ();
@@ -67,7 +72,7 @@ public function testGetWindowNames()
6772 $ this ->assertNotNull ($ windowNames [2 ]);
6873 }
6974
70- public function testResizeWindow ()
75+ public function testResizeWindow (): void
7176 {
7277 $ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
7378 $ session = $ this ->getSession ();
@@ -94,17 +99,33 @@ public function testResizeWindow()
9499 $ this ->assertTrue ($ session ->evaluateScript ($ jsWindowSizeScript ));
95100 }
96101
97- public function testWindowMaximize ()
102+ public function testWindowMaximize (): void
98103 {
99104 $ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
100105 $ session = $ this ->getSession ();
101-
102- $ session ->maximizeWindow ();
103- $ session ->wait (1000 , 'false ' );
104-
105- $ unusedWidth = $ session ->evaluateScript ('screen.availWidth - window.outerWidth ' );
106- $ unusedHeight = $ session ->evaluateScript ('screen.availHeight - window.outerHeight ' );
107- $ this ->assertLessThanOrEqual (0 , $ unusedWidth );
108- $ this ->assertLessThanOrEqual (0 , $ unusedHeight );
106+ $ popupName = 'testPopup ' ;
107+ $ createWindowJs = "window.open('about:blank', ' $ popupName', 'left=20,top=40,width=300,height=200') " ;
108+ $ getWindowPosJs = '
109+ return {
110+ top: window.screenY,
111+ left: window.screenX,
112+ right: window.screenX + window.innerWidth,
113+ bottom: window.screenX + window.innerHeight
114+ }
115+ ' ;
116+ $ session ->executeScript ($ createWindowJs );
117+ $ session ->switchToWindow ($ popupName );
118+ $ oldDim = (array )$ session ->evaluateScript ($ getWindowPosJs );
119+
120+ $ session ->maximizeWindow ($ popupName );
121+ $ newDim = (array )$ session ->evaluateScript ($ getWindowPosJs );
122+
123+ foreach (array_keys ($ oldDim ) as $ name ) {
124+ $ this ->assertNotEquals (
125+ $ oldDim [$ name ],
126+ $ newDim [$ name ],
127+ "The popup's $ name position should not be the same after maximizing "
128+ );
129+ }
109130 }
110131}
0 commit comments