Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"php-coveralls/php-coveralls": "^2.4",
"php-mock/php-mock-phpunit": "^1.1 || ^2.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpunit/phpunit": "^5.7 || ^7 || ^8 || ^9",
"phpunit/phpunit": "^5.7,>=5.7.15 || ^7 || ^8 || ^9",
Comment thread
oleg-andreyev marked this conversation as resolved.
"squizlabs/php_codesniffer": "^3.5",
"symfony/var-dumper": "^3.3 || ^4.0 || ^5.0"
},
Expand Down
32 changes: 31 additions & 1 deletion lib/WebDriverDimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ class WebDriverDimension
*/
private $width;

/**
* @var int|float|null
*/
private $x;

/**
* @var int|float|null
*/
private $y;

/**
* @param int|float $width
* @param int|float $height
* @param int|float|null $x
* @param int|float|null $y
*/
public function __construct($width, $height)
public function __construct($width, $height, $x = null, $y = null)
{
$this->width = $width;
$this->height = $height;
$this->x = $x;
$this->y = $y;
}

/**
Expand Down Expand Up @@ -56,4 +70,20 @@ public function equals(self $dimension)
{
return $this->height === $dimension->getHeight() && $this->width === $dimension->getWidth();
}

/**
* @return float|int|null
*/
public function getScreenX()
{
return $this->x;
}

/**
* @return float|int|null
*/
public function getScreenY()
{
return $this->y;
}
}
92 changes: 75 additions & 17 deletions lib/WebDriverWindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,69 +59,94 @@ public function getSize()
[':windowHandle' => 'current']
);

if (!$this->isW3cCompliant) {
$dimension = $this->getPosition();
$dimensionArray = ['x' => $dimension->getX(), 'y' => $dimension->getY()];
} else {
$dimensionArray = ['x' => $size['x'], 'y' => $size['y']];
}

return new WebDriverDimension(
$size['width'],
$size['height']
$size['height'],
$dimensionArray['x'],
$dimensionArray['y']
);
}

/**
* Minimizes the current window if it is not already minimized.
*
* @return WebDriverWindow The instance.
* @return WebDriverDimension
*/
public function minimize()
{
if (!$this->isW3cCompliant) {
throw new UnsupportedOperationException('Minimize window is only supported in W3C mode');
}

$this->executor->execute(DriverCommand::MINIMIZE_WINDOW, []);
$size = $this->executor->execute(DriverCommand::MINIMIZE_WINDOW, []);

return $this;
return new WebDriverDimension(
$size['width'],
$size['height'],
$size['x'],
$size['y']
);
}

/**
* Maximizes the current window if it is not already maximized
*
* @return WebDriverWindow The instance.
* @return WebDriverDimension
*/
public function maximize()
{
if ($this->isW3cCompliant) {
$this->executor->execute(DriverCommand::MAXIMIZE_WINDOW, []);
$size = $this->executor->execute(DriverCommand::MAXIMIZE_WINDOW, []);
} else {
$this->executor->execute(
$size = $this->executor->execute(
DriverCommand::MAXIMIZE_WINDOW,
[':windowHandle' => 'current']
);
}

return $this;
return new WebDriverDimension(
$size['width'],
$size['height'],
$size['x'],
$size['y']
);
}

/**
* Makes the current window full screen.
*
* @return WebDriverWindow The instance.
* @return WebDriverDimension
*/
public function fullscreen()
{
if (!$this->isW3cCompliant) {
throw new UnsupportedOperationException('The Fullscreen window command is only supported in W3C mode');
}

$this->executor->execute(DriverCommand::FULLSCREEN_WINDOW, []);
$size = $this->executor->execute(DriverCommand::FULLSCREEN_WINDOW, []);

return $this;
return new WebDriverDimension(
$size['width'],
$size['height'],
$size['x'],
$size['y']
);
}

/**
* Set the size of the current window. This will change the outer window
* dimension, not just the view port.
*
* @param WebDriverDimension $size
* @return WebDriverWindow The instance.
*
* @return WebDriverDimension
*/
public function setSize(WebDriverDimension $size)
{
Expand All @@ -130,17 +155,28 @@ public function setSize(WebDriverDimension $size)
'height' => $size->getHeight(),
':windowHandle' => 'current',
];
$this->executor->execute(DriverCommand::SET_WINDOW_SIZE, $params);

return $this;
$size = $this->executor->execute(DriverCommand::SET_WINDOW_SIZE, $params);

if (!$this->isW3cCompliant) {
return $this->getSize();
}

return new WebDriverDimension(
$size['width'],
$size['height'],
$size['x'],
$size['y']
);
}

/**
* Set the position of the current window. This is relative to the upper left
* corner of the screen.
*
* @param WebDriverPoint $position
* @return WebDriverWindow The instance.
*
* @return WebDriverDimension
*/
public function setPosition(WebDriverPoint $position)
{
Expand All @@ -149,9 +185,19 @@ public function setPosition(WebDriverPoint $position)
'y' => $position->getY(),
':windowHandle' => 'current',
];
$this->executor->execute(DriverCommand::SET_WINDOW_POSITION, $params);

return $this;
$size = $this->executor->execute(DriverCommand::SET_WINDOW_POSITION, $params);

if (!$this->isW3cCompliant) {
return $this->getSize();
}

return new WebDriverDimension(
$size['width'],
$size['height'],
$size['x'],
$size['y']
);
}

/**
Expand All @@ -161,6 +207,12 @@ public function setPosition(WebDriverPoint $position)
*/
public function getScreenOrientation()
{
if ($this->isW3cCompliant) {
throw new UnsupportedOperationException(
'The Screen Orientation window command is only supported in OSS mode'
);
}

return $this->executor->execute(DriverCommand::GET_SCREEN_ORIENTATION);
}

Expand All @@ -174,6 +226,12 @@ public function getScreenOrientation()
*/
public function setScreenOrientation($orientation)
{
if ($this->isW3cCompliant) {
throw new UnsupportedOperationException(
'The Screen Orientation window command is only supported in OSS mode'
);
}

$orientation = mb_strtoupper($orientation);
if (!in_array($orientation, ['PORTRAIT', 'LANDSCAPE'])) {
throw new IndexOutOfBoundsException(
Expand Down
2 changes: 1 addition & 1 deletion scripts/apply-phpunit-patches.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# All commands below must no fail
set -e
set -ex

# Be in the root dir
cd "$(dirname $0)/../"
Expand Down
Loading