Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 329de08

Browse files
andrewnicolsOndraM
authored andcommitted
Add minimize window command
Part of #683
1 parent ed8c868 commit 329de08

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

lib/Remote/DriverCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class DriverCommand
151151
const GET_ELEMENT_PROPERTY = 'getElementProperty';
152152
const GET_NAMED_COOKIE = 'getNamedCookie';
153153
const TAKE_ELEMENT_SCREENSHOT = 'takeElementScreenshot';
154+
const MINIMIZE_WINDOW = 'minimizeWindow';
154155

155156
private function __construct()
156157
{

lib/Remote/HttpCommandExecutor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class HttpCommandExecutor implements WebDriverCommandExecutor
167167
DriverCommand::GET_WINDOW_SIZE => ['method' => 'GET', 'url' => '/session/:sessionId/window/rect'],
168168
DriverCommand::IMPLICITLY_WAIT => ['method' => 'POST', 'url' => '/session/:sessionId/timeouts'],
169169
DriverCommand::MAXIMIZE_WINDOW => ['method' => 'POST', 'url' => '/session/:sessionId/window/maximize'],
170+
DriverCommand::MINIMIZE_WINDOW => ['method' => 'POST', 'url' => '/session/:sessionId/window/minimize'],
170171
DriverCommand::SET_ALERT_VALUE => ['method' => 'POST', 'url' => '/session/:sessionId/alert/text'],
171172
DriverCommand::SET_SCRIPT_TIMEOUT => ['method' => 'POST', 'url' => '/session/:sessionId/timeouts'],
172173
DriverCommand::SET_TIMEOUT => ['method' => 'POST', 'url' => '/session/:sessionId/timeouts'],

lib/WebDriverOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function timeouts()
162162
*/
163163
public function window()
164164
{
165-
return new WebDriverWindow($this->executor);
165+
return new WebDriverWindow($this->executor, $this->isW3cCompliant);
166166
}
167167

168168
/**

lib/WebDriverWindow.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Facebook\WebDriver;
1717

1818
use Facebook\WebDriver\Exception\IndexOutOfBoundsException;
19+
use Facebook\WebDriver\Exception\UnsupportedOperationException;
1920
use Facebook\WebDriver\Remote\DriverCommand;
2021
use Facebook\WebDriver\Remote\ExecuteMethod;
2122

@@ -28,10 +29,15 @@ class WebDriverWindow
2829
* @var ExecuteMethod
2930
*/
3031
protected $executor;
32+
/**
33+
* @var bool
34+
*/
35+
protected $isW3cCompliant;
3136

32-
public function __construct(ExecuteMethod $executor)
37+
public function __construct(ExecuteMethod $executor, $isW3cCompliant = false)
3338
{
3439
$this->executor = $executor;
40+
$this->isW3cCompliant = $isW3cCompliant;
3541
}
3642

3743
/**
@@ -72,6 +78,22 @@ public function getSize()
7278
);
7379
}
7480

81+
/**
82+
* Minimizes the current window if it is not already minimized.
83+
*
84+
* @return WebDriverWindow The instance.
85+
*/
86+
public function minimize()
87+
{
88+
if (!$this->isW3cCompliant) {
89+
throw new UnsupportedOperationException('Minimize window is only supported in W3C mode');
90+
}
91+
92+
$this->executor->execute(DriverCommand::MINIMIZE_WINDOW, []);
93+
94+
return $this;
95+
}
96+
7597
/**
7698
* Maximizes the current window if it is not already maximized
7799
*

tests/functional/WebDriverWindowTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ public function testShouldMaximizeWindow()
4848
$this->assertGreaterThanOrEqual($sizeBefore->getHeight(), $sizeAfter->getHeight());
4949
}
5050

51+
public function testShouldMinimizeWindow()
52+
{
53+
self::skipForJsonWireProtocol('"minimize" window is not supported in JsonWire protocol');
54+
55+
$this->assertSame('visible', $this->driver->executeScript('return document.visibilityState;'));
56+
57+
$this->driver->manage()
58+
->window()
59+
->minimize();
60+
61+
$this->assertSame('hidden', $this->driver->executeScript('return document.visibilityState;'));
62+
}
63+
5164
/**
5265
* @group exclude-saucelabs
5366
*/

0 commit comments

Comments
 (0)