Skip to content

Commit

Permalink
fixes #81 - completing update to WebDriver W3C Candidate Recommendati…
Browse files Browse the repository at this point in the history
…on 26 September 2017
  • Loading branch information
robocoder committed Oct 5, 2017
1 parent ad158ad commit 485a781
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 54 deletions.
2 changes: 2 additions & 0 deletions lib/WebDriver/Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*/
final class Frame extends AbstractWebDriver
{
const WEBDRIVER_FRAME_ID = 'frame-075b-4da1-b6ba-e579c2d3230a';

/**
* {@inheritdoc}
*/
Expand Down
90 changes: 90 additions & 0 deletions lib/WebDriver/LegacyWindow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Copyright 2011-2017 Anthon Pang. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package WebDriver
*
* @author Anthon Pang <[email protected]>
* @author Fabrizio Branca <[email protected]>
*/

namespace WebDriver;

/**
* WebDriver\LegacyWindow class
*
* @package WebDriver
*
* @method array getSize() Get size of the window.
* @method void postSize($json) Change the size of the window.
* @method array getPosition() Get position of the window.
* @method void postPosition($json) Change position of the window.
* @method void maximize() Maximize the window if not already maximized.
*/
final class LegacyWindow extends AbstractWebDriver
{
/**
* Window handle
*
* @var string
*/
private $windowHandle;

/**
* {@inheritdoc}
*/
protected function methods()
{
return array(
// Legacy JSON Wire Protocol
'size' => array('GET', 'POST'),
'position' => array('GET', 'POST'),
'maximize' => array('POST'),
);
}

/**
* {@inheritdoc}
*/
protected function obsoleteMethods()
{
return array(
'restore' => array('POST'),
);
}

/**
* Get window handle
*
* @return string
*/
public function getHandle()
{
return $this->windowHandle;
}

/**
* Constructor
*
* @param string $url URL
* @param string $windowHandle Window handle
*/
public function __construct($url, $windowHandle)
{
$this->windowHandle = $windowHandle;

parent::__construct($url . '/' . $windowHandle);
}
}
51 changes: 33 additions & 18 deletions lib/WebDriver/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
* @method void postLocation($jsonCoordinates) Set the current geo location.
* @method boolean getBrowser_connection() Is browser online?
* @method void postBrowser_connection($jsonState) Set browser online.
* @method array postActions() Perform Actions
* @method array deleteActions() Release Actions
*/
final class Session extends Container
{
Expand All @@ -72,18 +74,20 @@ final class Session extends Container
protected function methods()
{
return array(
'window_handle' => array('GET'),
'window_handles' => array('GET'),
'url' => array('GET', 'POST'), // alternate for POST, use open($url)
'forward' => array('POST'),
'back' => array('POST'),
'refresh' => array('POST'),
'execute' => array('POST'),
'execute_async' => array('POST'),
'screenshot' => array('GET'),
'cookie' => array('GET', 'POST'), // for DELETE, use deleteAllCookies()
'source' => array('GET'),
'title' => array('GET'),
'actions' => array('POST', 'DELETE'),

// specific to Java SeleniumServer
'file' => array('POST'),

// Legacy JSON Wire Protocol
'keys' => array('POST'),
'orientation' => array('GET', 'POST'),
'alert_text' => array('GET', 'POST'),
Expand All @@ -97,9 +101,10 @@ protected function methods()
'execute_sql' => array('POST'),
'location' => array('GET', 'POST'),
'browser_connection' => array('GET', 'POST'),

// specific to Java SeleniumServer
'file' => array('POST'),
'window_handle' => array('GET'),
'window_handles' => array('GET'),
'execute' => array('POST'),
'execute_async' => array('POST'),
);
}

Expand Down Expand Up @@ -220,14 +225,25 @@ public function deleteCookie($cookieName)
}

/**
* window methods: /session/:sessionId/window (POST, DELETE)
* - $session->window() - close current window
* - $session->window($name) - set focus
* - $session->window($window_handle)->method() - chaining
* Window method chaining, e.g.,
* - $session->window($handle)->method() - chaining
*
* @return \WebDriver\Window|\WebDriver\Session
* @return \WebDriver\Window
*/
public function window()
{
return new Window($this->url . '/window');
}

/**
* Legacy window methods: /session/:sessionId/window (POST, DELETE)
* - $session->legacyWindow() - close current window
* - $session->legacyWindow($name) - set focus
* - $session->legacyWindow($window_handle)->method() - chaining
*
* @return \WebDriver\LegacyWindow|\WebDriver\Session
*/
public function legacyWindow()
{
// close current window
if (func_num_args() === 0) {
Expand All @@ -246,7 +262,7 @@ public function window()
}

// chaining
return new Window($this->url . '/window', $arg);
return new LegacyWindow($this->url . '/window', $arg);
}

/**
Expand All @@ -270,7 +286,7 @@ public function deleteWindow()
*/
public function focusWindow($name)
{
$this->curl('POST', '/window', array('name' => $name));
$this->curl('POST', '/window', array('name' => $name, 'handle' => $name));

return $this;
}
Expand Down Expand Up @@ -389,7 +405,7 @@ public function session_storage()

/**
* application cache chaining, e.g.,
* - $session->application_cache()->status()
* - $session->application_cache()->method() - chaining
*
* @return \WebDriver\ApplicationCache
*/
Expand Down Expand Up @@ -428,7 +444,7 @@ public function log()

/**
* alert method chaining, e.g.,
* - $session->alert()->text()
* - $session->alert()->method() - chaining
*
* @return mixed
*/
Expand All @@ -439,9 +455,8 @@ public function alert()

/**
* script execution method chaining, e.g.,
* - $session->execute()->sync()
* - $session->execute()->async()
* - $session->execute() - fallback for legacy JSON Wire Protocol
* - $session->execute()->method() - chaining
*
* @return mixed
*/
Expand Down
51 changes: 15 additions & 36 deletions lib/WebDriver/Window.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,28 @@
*
* @package WebDriver
*
* @method array getSize() Get size of the window.
* @method void postSize($json) Change the size of the window.
* @method array getPosition() Get position of the window.
* @method void postPosition($json) Change position of the window.
* @method void maximize() Maximize the window if not already maximized.
* @method array maximize() Maximize the window if not already maximized.
* @method array minimize() Minimize Window
* @method array fullscreen() Fullscreen Window
* @method array getRect() Get Window Rect
* @method array postRect() Set Window Rect
* @method array handles() Get Window Handles
*/
final class Window extends AbstractWebDriver
{
/**
* Window handle
*
* @var string
*/
private $windowHandle;
const WEBDRIVER_WINDOW_ID = 'window-fcc6-11e5-b4f8-330a88ab9d7f';

/**
* {@inheritdoc}
*/
protected function methods()
{
return array(
'size' => array('GET', 'POST'),
'position' => array('GET', 'POST'),
'maximize' => array('POST'),
);
}

/**
* {@inheritdoc}
*/
protected function obsoleteMethods()
{
return array(
'restore' => array('POST'),
'minimize' => array('POST'),
'fullscreen' => array('POST'),
'rect' => array('GET', 'POST'),
'handles' => array('GET'),
);
}

Expand All @@ -71,19 +59,10 @@ protected function obsoleteMethods()
*/
public function getHandle()
{
return $this->windowHandle;
}

/**
* Constructor
*
* @param string $url URL
* @param string $windowHandle Window handle
*/
public function __construct($url, $windowHandle)
{
$this->windowHandle = $windowHandle;
$result = $this->curl('GET', $this->url);

parent::__construct($url . '/' . $windowHandle);
return array_key_exists(self::WEBDRIVER_WINDOW_ID, $result['value'])
? $result['value'][self::WEBDRIVER_WINDOW_ID]
: $result['value'];
}
}

0 comments on commit 485a781

Please sign in to comment.