123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace Facebook\WebDriver;
- use Facebook\WebDriver\Exception\IndexOutOfBoundsException;
- use Facebook\WebDriver\Remote\DriverCommand;
- use Facebook\WebDriver\Remote\ExecuteMethod;
- class WebDriverWindow
- {
-
- protected $executor;
- public function __construct(ExecuteMethod $executor)
- {
- $this->executor = $executor;
- }
-
- public function getPosition()
- {
- $position = $this->executor->execute(
- DriverCommand::GET_WINDOW_POSITION,
- [':windowHandle' => 'current']
- );
- return new WebDriverPoint(
- $position['x'],
- $position['y']
- );
- }
-
- public function getSize()
- {
- $size = $this->executor->execute(
- DriverCommand::GET_WINDOW_SIZE,
- [':windowHandle' => 'current']
- );
- return new WebDriverDimension(
- $size['width'],
- $size['height']
- );
- }
-
- public function maximize()
- {
- $this->executor->execute(
- DriverCommand::MAXIMIZE_WINDOW,
- [':windowHandle' => 'current']
- );
- return $this;
- }
-
- public function setSize(WebDriverDimension $size)
- {
- $params = [
- 'width' => $size->getWidth(),
- 'height' => $size->getHeight(),
- ':windowHandle' => 'current',
- ];
- $this->executor->execute(DriverCommand::SET_WINDOW_SIZE, $params);
- return $this;
- }
-
- public function setPosition(WebDriverPoint $position)
- {
- $params = [
- 'x' => $position->getX(),
- 'y' => $position->getY(),
- ':windowHandle' => 'current',
- ];
- $this->executor->execute(DriverCommand::SET_WINDOW_POSITION, $params);
- return $this;
- }
-
- public function getScreenOrientation()
- {
- return $this->executor->execute(DriverCommand::GET_SCREEN_ORIENTATION);
- }
-
- public function setScreenOrientation($orientation)
- {
- $orientation = mb_strtoupper($orientation);
- if (!in_array($orientation, ['PORTRAIT', 'LANDSCAPE'])) {
- throw new IndexOutOfBoundsException(
- 'Orientation must be either PORTRAIT, or LANDSCAPE'
- );
- }
- $this->executor->execute(
- DriverCommand::SET_SCREEN_ORIENTATION,
- ['orientation' => $orientation]
- );
- return $this;
- }
- }
|