From 095ddf9ef69a02fce5ca9183d02a8cbea84e3501 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Sat, 17 Jun 2023 14:11:20 +0200 Subject: [PATCH] Improve testWindowMaximize --- tests/Js/WindowTest.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/tests/Js/WindowTest.php b/tests/Js/WindowTest.php index e667600..6fbd7c3 100644 --- a/tests/Js/WindowTest.php +++ b/tests/Js/WindowTest.php @@ -98,12 +98,29 @@ public function testWindowMaximize(): void { $this->getSession()->visit($this->pathTo('/index.html')); $session = $this->getSession(); - - $session->maximizeWindow(); - $session->wait(1000, 'false'); - - $script = 'return Math.abs(screen.availHeight - window.outerHeight);'; - - $this->assertLessThanOrEqual(100, $session->evaluateScript($script)); + $popupName = 'testPopup'; + $createWindowJs = "window.open('about:blank', '$popupName', 'left=20,top=40,width=300,height=200')"; + $getWindowPosJs = ' + return { + top: window.screenY, + left: window.screenX, + right: window.screenX + window.innerWidth, + bottom: window.screenX + window.innerHeight + } + '; + $session->executeScript($createWindowJs); + $session->switchToWindow($popupName); + $oldDim = (array)$session->evaluateScript($getWindowPosJs); + + $session->maximizeWindow($popupName); + $newDim = (array)$session->evaluateScript($getWindowPosJs); + + foreach (array_keys($oldDim) as $name) { + $this->assertNotEquals( + $oldDim[$name], + $newDim[$name], + "The popup's $name position should not be the same after maximizing" + ); + } } }