Skip to content

Commit

Permalink
Merge pull request #84 from uuf6429/improve-resize-window
Browse files Browse the repository at this point in the history
Refactor testResizeWindow; increase window size for MSEdge
  • Loading branch information
stof authored Oct 17, 2023
2 parents 307efdc + 4fb1462 commit 5bf4c47
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tests/Js/WindowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,28 @@ public function testResizeWindow(): void
{
$this->getSession()->visit($this->pathTo('/index.html'));
$session = $this->getSession();
$expectedWidth = 640;
$expectedHeight = 480;

$session->resizeWindow(400, 300);
$session->resizeWindow($expectedWidth, $expectedHeight);
$session->wait(1000, 'false');
$jsWindowSizeScript = <<<'JS'
(function(){
var boolSizeCheck = Math.abs(window.outerHeight - 300) <= 100 && Math.abs(window.outerWidth - 400) <= 100;
if (boolSizeCheck){
return true;
}
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
boolSizeCheck = Math.abs(y - 300) <= 100 && Math.abs(x - 400) <= 100;
return boolSizeCheck;

$jsWindowSizeScript = <<<"JS"
(function () {
var check = function (actualWidth, actualHeight) {
return Math.abs(actualWidth - $expectedWidth) <= 100
&& Math.abs(actualHeight - $expectedHeight) <= 100;
},
htmlElem = document.documentElement,
bodyElem = document.getElementsByTagName('body')[0];
return check(window.outerWidth, window.outerHeight)
|| check(
window.innerWidth || htmlElem.clientWidth || bodyElem.clientWidth,
window.innerHeight || htmlElem.clientHeight || bodyElem.clientHeight
);
})();
JS;

$this->assertTrue($session->evaluateScript($jsWindowSizeScript));
}

Expand Down

0 comments on commit 5bf4c47

Please sign in to comment.