1
1
<?php
2
2
3
+ /**
4
+ * @noinspection PhpUnhandledExceptionInspection
5
+ * @noinspection PhpRedundantOptionalArgumentInspection
6
+ */
7
+
3
8
namespace Behat \Mink \Tests \Driver \Js ;
4
9
5
10
use Behat \Mink \Tests \Driver \TestCase ;
6
11
7
12
final class WindowTest extends TestCase
8
13
{
9
- public function testWindow ()
14
+ public function testWindow (): void
10
15
{
11
16
$ this ->getSession ()->visit ($ this ->pathTo ('/window.html ' ));
12
17
$ session = $ this ->getSession ();
@@ -47,7 +52,7 @@ public function testWindowName(): void
47
52
$ this ->assertContains ($ windowName , $ windowNames , 'The current window name should be one of the available window names. ' );
48
53
}
49
54
50
- public function testGetWindowNames ()
55
+ public function testGetWindowNames (): void
51
56
{
52
57
$ this ->getSession ()->visit ($ this ->pathTo ('/window.html ' ));
53
58
$ session = $ this ->getSession ();
@@ -67,7 +72,7 @@ public function testGetWindowNames()
67
72
$ this ->assertNotNull ($ windowNames [2 ]);
68
73
}
69
74
70
- public function testResizeWindow ()
75
+ public function testResizeWindow (): void
71
76
{
72
77
$ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
73
78
$ session = $ this ->getSession ();
@@ -94,17 +99,33 @@ public function testResizeWindow()
94
99
$ this ->assertTrue ($ session ->evaluateScript ($ jsWindowSizeScript ));
95
100
}
96
101
97
- public function testWindowMaximize ()
102
+ public function testWindowMaximize (): void
98
103
{
99
104
$ this ->getSession ()->visit ($ this ->pathTo ('/index.html ' ));
100
105
$ 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
+ }
109
130
}
110
131
}
0 commit comments