Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test resize and maximize window also prior to page visit #10

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/Js/WindowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ public function testResizeWindow()
$this->assertTrue($session->evaluateScript($jsWindowSizeScript));
}

public function testResizeWindowBeforePageVisit()
{
$session = $this->getSession();
$session->resizeWindow(400, 300);
$session->wait(1000, 'false');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the session to wait without a meaningful JS condition (i.e. one subject to change) is useless. Just use sleep.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


$session->visit($this->pathTo('/index.html'));

$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;
})();
JS;

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

public function testWindowMaximize()
{
$this->getSession()->visit($this->pathTo('/index.html'));
Expand All @@ -94,4 +122,18 @@ public function testWindowMaximize()

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

public function testWindowMaximizeBeforePageVisit()
{
$session = $this->getSession();

$session->maximizeWindow();
$session->wait(1000, 'false');

$session->visit($this->pathTo('/index.html'));

$script = 'return Math.abs(screen.availHeight - window.outerHeight) <= 100;';

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