Skip to content

Commit 485a781

Browse files
committed
fixes #81 - completing update to WebDriver W3C Candidate Recommendation 26 September 2017
1 parent ad158ad commit 485a781

File tree

4 files changed

+140
-54
lines changed

4 files changed

+140
-54
lines changed

lib/WebDriver/Frame.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
*/
3131
final class Frame extends AbstractWebDriver
3232
{
33+
const WEBDRIVER_FRAME_ID = 'frame-075b-4da1-b6ba-e579c2d3230a';
34+
3335
/**
3436
* {@inheritdoc}
3537
*/

lib/WebDriver/LegacyWindow.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright 2011-2017 Anthon Pang. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* @package WebDriver
18+
*
19+
* @author Anthon Pang <[email protected]>
20+
* @author Fabrizio Branca <[email protected]>
21+
*/
22+
23+
namespace WebDriver;
24+
25+
/**
26+
* WebDriver\LegacyWindow class
27+
*
28+
* @package WebDriver
29+
*
30+
* @method array getSize() Get size of the window.
31+
* @method void postSize($json) Change the size of the window.
32+
* @method array getPosition() Get position of the window.
33+
* @method void postPosition($json) Change position of the window.
34+
* @method void maximize() Maximize the window if not already maximized.
35+
*/
36+
final class LegacyWindow extends AbstractWebDriver
37+
{
38+
/**
39+
* Window handle
40+
*
41+
* @var string
42+
*/
43+
private $windowHandle;
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
protected function methods()
49+
{
50+
return array(
51+
// Legacy JSON Wire Protocol
52+
'size' => array('GET', 'POST'),
53+
'position' => array('GET', 'POST'),
54+
'maximize' => array('POST'),
55+
);
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
protected function obsoleteMethods()
62+
{
63+
return array(
64+
'restore' => array('POST'),
65+
);
66+
}
67+
68+
/**
69+
* Get window handle
70+
*
71+
* @return string
72+
*/
73+
public function getHandle()
74+
{
75+
return $this->windowHandle;
76+
}
77+
78+
/**
79+
* Constructor
80+
*
81+
* @param string $url URL
82+
* @param string $windowHandle Window handle
83+
*/
84+
public function __construct($url, $windowHandle)
85+
{
86+
$this->windowHandle = $windowHandle;
87+
88+
parent::__construct($url . '/' . $windowHandle);
89+
}
90+
}

lib/WebDriver/Session.php

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
* @method void postLocation($jsonCoordinates) Set the current geo location.
5959
* @method boolean getBrowser_connection() Is browser online?
6060
* @method void postBrowser_connection($jsonState) Set browser online.
61+
* @method array postActions() Perform Actions
62+
* @method array deleteActions() Release Actions
6163
*/
6264
final class Session extends Container
6365
{
@@ -72,18 +74,20 @@ final class Session extends Container
7274
protected function methods()
7375
{
7476
return array(
75-
'window_handle' => array('GET'),
76-
'window_handles' => array('GET'),
7777
'url' => array('GET', 'POST'), // alternate for POST, use open($url)
7878
'forward' => array('POST'),
7979
'back' => array('POST'),
8080
'refresh' => array('POST'),
81-
'execute' => array('POST'),
82-
'execute_async' => array('POST'),
8381
'screenshot' => array('GET'),
8482
'cookie' => array('GET', 'POST'), // for DELETE, use deleteAllCookies()
8583
'source' => array('GET'),
8684
'title' => array('GET'),
85+
'actions' => array('POST', 'DELETE'),
86+
87+
// specific to Java SeleniumServer
88+
'file' => array('POST'),
89+
90+
// Legacy JSON Wire Protocol
8791
'keys' => array('POST'),
8892
'orientation' => array('GET', 'POST'),
8993
'alert_text' => array('GET', 'POST'),
@@ -97,9 +101,10 @@ protected function methods()
97101
'execute_sql' => array('POST'),
98102
'location' => array('GET', 'POST'),
99103
'browser_connection' => array('GET', 'POST'),
100-
101-
// specific to Java SeleniumServer
102-
'file' => array('POST'),
104+
'window_handle' => array('GET'),
105+
'window_handles' => array('GET'),
106+
'execute' => array('POST'),
107+
'execute_async' => array('POST'),
103108
);
104109
}
105110

@@ -220,14 +225,25 @@ public function deleteCookie($cookieName)
220225
}
221226

222227
/**
223-
* window methods: /session/:sessionId/window (POST, DELETE)
224-
* - $session->window() - close current window
225-
* - $session->window($name) - set focus
226-
* - $session->window($window_handle)->method() - chaining
228+
* Window method chaining, e.g.,
229+
* - $session->window($handle)->method() - chaining
227230
*
228-
* @return \WebDriver\Window|\WebDriver\Session
231+
* @return \WebDriver\Window
229232
*/
230233
public function window()
234+
{
235+
return new Window($this->url . '/window');
236+
}
237+
238+
/**
239+
* Legacy window methods: /session/:sessionId/window (POST, DELETE)
240+
* - $session->legacyWindow() - close current window
241+
* - $session->legacyWindow($name) - set focus
242+
* - $session->legacyWindow($window_handle)->method() - chaining
243+
*
244+
* @return \WebDriver\LegacyWindow|\WebDriver\Session
245+
*/
246+
public function legacyWindow()
231247
{
232248
// close current window
233249
if (func_num_args() === 0) {
@@ -246,7 +262,7 @@ public function window()
246262
}
247263

248264
// chaining
249-
return new Window($this->url . '/window', $arg);
265+
return new LegacyWindow($this->url . '/window', $arg);
250266
}
251267

252268
/**
@@ -270,7 +286,7 @@ public function deleteWindow()
270286
*/
271287
public function focusWindow($name)
272288
{
273-
$this->curl('POST', '/window', array('name' => $name));
289+
$this->curl('POST', '/window', array('name' => $name, 'handle' => $name));
274290

275291
return $this;
276292
}
@@ -389,7 +405,7 @@ public function session_storage()
389405

390406
/**
391407
* application cache chaining, e.g.,
392-
* - $session->application_cache()->status()
408+
* - $session->application_cache()->method() - chaining
393409
*
394410
* @return \WebDriver\ApplicationCache
395411
*/
@@ -428,7 +444,7 @@ public function log()
428444

429445
/**
430446
* alert method chaining, e.g.,
431-
* - $session->alert()->text()
447+
* - $session->alert()->method() - chaining
432448
*
433449
* @return mixed
434450
*/
@@ -439,9 +455,8 @@ public function alert()
439455

440456
/**
441457
* script execution method chaining, e.g.,
442-
* - $session->execute()->sync()
443-
* - $session->execute()->async()
444458
* - $session->execute() - fallback for legacy JSON Wire Protocol
459+
* - $session->execute()->method() - chaining
445460
*
446461
* @return mixed
447462
*/

lib/WebDriver/Window.php

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,28 @@
2727
*
2828
* @package WebDriver
2929
*
30-
* @method array getSize() Get size of the window.
31-
* @method void postSize($json) Change the size of the window.
32-
* @method array getPosition() Get position of the window.
33-
* @method void postPosition($json) Change position of the window.
34-
* @method void maximize() Maximize the window if not already maximized.
30+
* @method array maximize() Maximize the window if not already maximized.
31+
* @method array minimize() Minimize Window
32+
* @method array fullscreen() Fullscreen Window
33+
* @method array getRect() Get Window Rect
34+
* @method array postRect() Set Window Rect
35+
* @method array handles() Get Window Handles
3536
*/
3637
final class Window extends AbstractWebDriver
3738
{
38-
/**
39-
* Window handle
40-
*
41-
* @var string
42-
*/
43-
private $windowHandle;
39+
const WEBDRIVER_WINDOW_ID = 'window-fcc6-11e5-b4f8-330a88ab9d7f';
4440

4541
/**
4642
* {@inheritdoc}
4743
*/
4844
protected function methods()
4945
{
5046
return array(
51-
'size' => array('GET', 'POST'),
52-
'position' => array('GET', 'POST'),
5347
'maximize' => array('POST'),
54-
);
55-
}
56-
57-
/**
58-
* {@inheritdoc}
59-
*/
60-
protected function obsoleteMethods()
61-
{
62-
return array(
63-
'restore' => array('POST'),
48+
'minimize' => array('POST'),
49+
'fullscreen' => array('POST'),
50+
'rect' => array('GET', 'POST'),
51+
'handles' => array('GET'),
6452
);
6553
}
6654

@@ -71,19 +59,10 @@ protected function obsoleteMethods()
7159
*/
7260
public function getHandle()
7361
{
74-
return $this->windowHandle;
75-
}
76-
77-
/**
78-
* Constructor
79-
*
80-
* @param string $url URL
81-
* @param string $windowHandle Window handle
82-
*/
83-
public function __construct($url, $windowHandle)
84-
{
85-
$this->windowHandle = $windowHandle;
62+
$result = $this->curl('GET', $this->url);
8663

87-
parent::__construct($url . '/' . $windowHandle);
64+
return array_key_exists(self::WEBDRIVER_WINDOW_ID, $result['value'])
65+
? $result['value'][self::WEBDRIVER_WINDOW_ID]
66+
: $result['value'];
8867
}
8968
}

0 commit comments

Comments
 (0)