-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathWindowTest.php
97 lines (75 loc) · 3.02 KB
/
WindowTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Behat\Mink\Tests\Driver\Js;
use Behat\Mink\Tests\Driver\TestCase;
final class WindowTest extends TestCase
{
public function testWindow()
{
$this->getSession()->visit($this->pathTo('/window.html'));
$session = $this->getSession();
$page = $session->getPage();
$webAssert = $this->getAssertSession();
$page->clickLink('Popup #1');
$session->switchToWindow(null);
$page->clickLink('Popup #2');
$session->switchToWindow(null);
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Main window div text', $el->getText());
$session->switchToWindow('popup_1');
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Popup#1 div text', $el->getText());
$session->switchToWindow('popup_2');
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Popup#2 div text', $el->getText());
$session->switchToWindow(null);
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Main window div text', $el->getText());
}
public function testGetWindowNames()
{
$this->getSession()->visit($this->pathTo('/window.html'));
$session = $this->getSession();
$page = $session->getPage();
$windowName = $this->getSession()->getWindowName();
$this->assertNotNull($windowName);
$page->clickLink('Popup #1');
$page->clickLink('Popup #2');
$windowNames = $this->getSession()->getWindowNames();
$this->assertNotNull($windowNames[0]);
$this->assertNotNull($windowNames[1]);
$this->assertNotNull($windowNames[2]);
}
public function testResizeWindow()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$session = $this->getSession();
$session->resizeWindow(400, 300);
$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;
})();
JS;
$this->assertTrue($session->evaluateScript($jsWindowSizeScript));
}
public function testWindowMaximize()
{
$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));
}
}