Skip to content

Commit eace059

Browse files
committed
Support for session/:sessionId/frame/parent to change focus to frame's parent
1 parent e5feb96 commit eace059

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

lib/WebDriver/Frame.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright 2011-2014 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 <apang@softwaredevelopment.ca>
20+
*/
21+
22+
namespace WebDriver;
23+
24+
/**
25+
* WebDriver\Frame class
26+
*
27+
* @package WebDriver
28+
*
29+
* @method void parentt() Change focus to the parent context.
30+
*/
31+
final class Frame extends AbstractWebDriver
32+
{
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
protected function methods()
37+
{
38+
return array(
39+
'parent' => array('POST'),
40+
);
41+
}
42+
}

lib/WebDriver/Session.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
* @method mixed execute($jsonScript) Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. (synchronous)
3838
* @method mixed execute_async($jsonScript) Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. (asynchronous)
3939
* @method string screenshot() Take a screenshot of the current page.
40-
* @method void frame($jsonFrameId) Change focus to another frame on the page.
4140
* @method array getCookie() Retrieve all cookies visible to the current page.
4241
* @method array postCookie($jsonCookie) Set a cookie.
4342
* @method string source() Get the current page source.
@@ -82,7 +81,6 @@ protected function methods()
8281
'execute' => array('POST'),
8382
'execute_async' => array('POST'),
8483
'screenshot' => array('GET'),
85-
'frame' => array('POST'),
8684
'cookie' => array('GET', 'POST'), // for DELETE, use deleteAllCookies()
8785
'source' => array('GET'),
8886
'title' => array('GET'),
@@ -277,12 +275,32 @@ public function focusWindow($name)
277275
return $this;
278276
}
279277

278+
/**
279+
* frame methods: /session/:sessionId/frame (POST)
280+
* - $session->frame($json) - change focus to another frame on the page
281+
* - $session->frame()->method() - chaining
282+
*
283+
* @return \WebDriver\Session|\WebDriver\Frame
284+
*/
285+
public function frame()
286+
{
287+
if (func_num_args() === 1) {
288+
$arg = func_get_arg(0); // json
289+
$this->curl('POST', '/frame', $arg);
290+
291+
return $this;
292+
}
293+
294+
// chaining
295+
return new Frame($this->url . '/frame');
296+
}
297+
280298
/**
281299
* timeouts methods: /session/:sessionId/timeouts (POST)
282300
* - $session->timeouts($json) - set timeout for an operation
283301
* - $session->timeouts()->method() - chaining
284302
*
285-
* @return \WebDriver\Timeouts
303+
* @return \WebDriver\Session|\WebDriver\Timeouts
286304
*/
287305
public function timeouts()
288306
{

0 commit comments

Comments
 (0)