|
17 | 17 | * @package WebDriver |
18 | 18 | * |
19 | 19 | * @method void accept_alert() Accepts the currently displayed alert dialog. |
20 | | - * @method array deleteActions() Release Actions |
21 | | - * @method array postActions() Perform Actions |
| 20 | + * @method array deleteActions() Release actions. |
| 21 | + * @method array postActions() Perform actions. |
22 | 22 | * @method string getAlert_text() Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. |
23 | 23 | * @method void postAlert_text($jsonText) Sends keystrokes to a JavaScript prompt() dialog. |
24 | 24 | * @method void back() Navigates backward in the browser history, if possible. |
|
40 | 40 | * @method void moveto($jsonCoordinates) Move the mouse by an offset of the specified element (or current mouse cursor). |
41 | 41 | * @method string getOrientation() Get the current browser orientation. |
42 | 42 | * @method void postOrientation($jsonOrientation) Set the current browser orientation. |
43 | | - * @method array print() Print Page |
| 43 | + * @method array print() Print page. |
44 | 44 | * @method void refresh() Refresh the current page. |
45 | 45 | * @method string screenshot() Take a screenshot of the current page. |
46 | 46 | * @method string source() Get the current page source. |
47 | 47 | * @method string title() Get the current page title. |
48 | | - * @method string url() Retrieve the URL of the current page |
49 | | - * @method void postUrl($jsonUrl) Navigate to a new URL |
| 48 | + * @method string url() Retrieve the URL of the current page. |
| 49 | + * @method void postUrl($jsonUrl) Navigate to a new URL. |
50 | 50 | * @method string window_handle() Retrieve the current window handle. |
51 | 51 | * @method array window_handles() Retrieve the list of all window handles available to the session. |
52 | 52 | */ |
@@ -96,7 +96,7 @@ protected function methods() |
96 | 96 | 'location' => array('GET', 'POST'), |
97 | 97 | 'moveto' => array('POST'), |
98 | 98 | 'orientation' => array('GET', 'POST'), |
99 | | - 'window_handle' => array('GET'), |
| 99 | + 'window_handle' => array('GET'), // see also getWindowHandle() |
100 | 100 | 'window_handles' => array('GET'), |
101 | 101 | ); |
102 | 102 | } |
@@ -218,55 +218,67 @@ public function deleteCookie($cookieName) |
218 | 218 | } |
219 | 219 |
|
220 | 220 | /** |
221 | | - * Window method chaining, e.g., |
222 | | - * - $session->window($handle)->method() - chaining |
| 221 | + * Get window handle: /session/:sessionId/window (GET) |
| 222 | + * : /session/:sessionId/window_handle (GET) |
| 223 | + * - $session->getWindowHandle() |
223 | 224 | * |
224 | | - * @return \WebDriver\Window |
| 225 | + * An alternative to $session->window()->getHandle() |
| 226 | + * |
| 227 | + * @return mixed |
225 | 228 | */ |
226 | | - public function window() |
| 229 | + public function getWindowHandle() |
227 | 230 | { |
228 | | - // legacy window methods |
229 | | - if ($this->legacy) { |
230 | | - return call_user_func_array(array($this, 'legacyWindow'), func_get_args()); |
231 | | - } |
| 231 | + $result = $this->curl('GET', $this->legacy ? '/window_handle' : '/window'); |
232 | 232 |
|
233 | | - return new Window($this->url . '/window'); |
| 233 | + return $result['value']; |
234 | 234 | } |
235 | 235 |
|
236 | 236 | /** |
237 | | - * Legacy window methods: /session/:sessionId/window (POST, DELETE) |
238 | | - * - $session->legacyWindow() - close current window |
239 | | - * - $session->legacyWindow($name) - set focus |
240 | | - * - $session->legacyWindow($window_handle)->method() - chaining |
| 237 | + * New window: /session/:sessionId/window/new (POST) |
| 238 | + * - $session->newWindow($type) |
241 | 239 | * |
242 | | - * @deprecated |
| 240 | + * @internal "new" is a reserved keyword in PHP, so $session->window()->new() isn't possible |
243 | 241 | * |
244 | | - * @return \WebDriver\LegacyWindow|\WebDriver\Session |
| 242 | + * @return \WebDriver\Window |
245 | 243 | */ |
246 | | - public function legacyWindow() |
| 244 | + public function newWindow($type) |
247 | 245 | { |
248 | | - // close current window |
249 | | - if (func_num_args() === 0) { |
250 | | - $this->curl('DELETE', '/window'); |
| 246 | + $arg = func_get_arg(0); // json |
251 | 247 |
|
252 | | - return $this; |
253 | | - } |
| 248 | + $result = $this->curl('POST', '/window/new', $arg); |
| 249 | + |
| 250 | + return $result['value']; |
| 251 | + } |
| 252 | + |
| 253 | + /** |
| 254 | + * window method chaining: /session/:sessionId/window (POST |
| 255 | + * - $session->window($jsonHandle) - set focus |
| 256 | + * - $session->window($handle)->method() - chaining |
| 257 | + * - $session->window()->method() - chaining |
| 258 | + * |
| 259 | + * @return \WebDriver\Session|\WebDriver\Window|\WebDriver\LegacyWindow |
| 260 | + */ |
| 261 | + public function window() |
| 262 | + { |
| 263 | + $arg = null; |
254 | 264 |
|
255 | | - // set focus |
256 | | - $arg = func_get_arg(0); // window handle or name attribute |
| 265 | + // set window focus / switch to window |
| 266 | + if (func_num_args() === 1) { |
| 267 | + $arg = func_get_arg(0); // window handle or name attribute |
257 | 268 |
|
258 | | - if (is_array($arg)) { |
259 | | - $this->curl('POST', '/window', $arg); |
| 269 | + if (is_array($arg)) { |
| 270 | + $this->curl('POST', '/window', $arg); |
260 | 271 |
|
261 | | - return $this; |
| 272 | + return $this; |
| 273 | + } |
262 | 274 | } |
263 | 275 |
|
264 | | - // chaining |
265 | | - return new LegacyWindow($this->url . '/window', $arg); |
| 276 | + // chaining (with optional handle in $arg) |
| 277 | + return $this->legacy ? new LegacyWindow($this->url . '/window', $arg) : new Window($this->url . '/window', $arg); |
266 | 278 | } |
267 | 279 |
|
268 | 280 | /** |
269 | | - * Delete window: /session/:sessionId/window (DELETE) |
| 281 | + * Close window: /session/:sessionId/window (DELETE) |
270 | 282 | * |
271 | 283 | * @return \WebDriver\Session |
272 | 284 | */ |
|
0 commit comments