Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit acf1f4d

Browse files
author
jameshd
committed
Merge remote-tracking branch 'facebook/master'
2 parents 03aca1f + da9b3f9 commit acf1f4d

File tree

6 files changed

+117
-64
lines changed

6 files changed

+117
-64
lines changed

lib/WebDriverTargetLocator.php

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,24 @@
1616
/**
1717
* Used to locate a given frame or window.
1818
*/
19-
class WebDriverTargetLocator {
20-
21-
protected $executor;
22-
protected $driver;
23-
24-
public function __construct($executor, $driver) {
25-
$this->executor = $executor;
26-
$this->driver = $driver;
27-
}
19+
interface WebDriverTargetLocator {
2820

2921
/**
3022
* Switch to the main document if the page contains iframes. Otherwise, switch
3123
* to the first frame on the page.
3224
*
3325
* @return WebDriver The driver focused on the top window or the first frame.
3426
*/
35-
public function defaultContent() {
36-
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, array());
37-
38-
return $this->driver;
39-
}
27+
public function defaultContent();
4028

4129
/**
4230
* Switch to the iframe by its id or name.
4331
*
4432
* @param WebDriverElement|string $frame The WebDriverElement,
45-
the id or the name of the frame.
33+
* the id or the name of the frame.
4634
* @return WebDriver The driver focused on the given frame.
4735
*/
48-
public function frame($frame) {
49-
if ($frame instanceof WebDriverElement) {
50-
$id = array('ELEMENT' => $frame->getID());
51-
} else {
52-
$id = (string)$frame;
53-
}
54-
55-
$params = array('id' => $id);
56-
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params);
57-
58-
return $this->driver;
59-
}
36+
public function frame($frame);
6037

6138
/**
6239
* Switch the focus to another window by its handle.
@@ -65,20 +42,21 @@ public function frame($frame) {
6542
* @return WebDriver Tge driver focused on the given window.
6643
* @see WebDriver::getWindowHandles
6744
*/
68-
public function window($handle) {
69-
$params = array('name' => (string)$handle);
70-
$this->executor->execute(DriverCommand::SWITCH_TO_WINDOW, $params);
71-
72-
return $this->driver;
73-
}
45+
public function window($handle);
7446

7547
/**
7648
* Switch to the currently active modal dialog for this particular driver
7749
* instance.
7850
*
7951
* @return WebDriverAlert
8052
*/
81-
public function alert() {
82-
return new WebDriverAlert($this->executor);
83-
}
53+
public function alert();
54+
55+
/**
56+
* Switches to the element that currently has focus within the document
57+
* currently "switched to", or the body element if this cannot be detected.
58+
*
59+
* @return WebDriverElement
60+
*/
61+
public function activeElement();
8462
}

lib/__init__.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
require_once('remote/FileDetector.php');
2525
require_once('WebDriverCapabilities.php');
2626
require_once('remote/ExecuteMethod.php');
27+
require_once('WebDriverTargetLocator.php');
2728

2829
// abstract class
2930
require_once('interactions/internal/WebDriverKeysRelatedAction.php');
@@ -48,7 +49,6 @@
4849
require_once('WebDriverPlatform.php');
4950
require_once('WebDriverPoint.php');
5051
require_once('WebDriverSelect.php');
51-
require_once('WebDriverTargetLocator.php');
5252
require_once('WebDriverTimeouts.php');
5353
require_once('WebDriverWait.php');
5454
require_once('WebDriverWindow.php');
@@ -85,6 +85,7 @@
8585
require_once('remote/WebDriverCapabilityType.php');
8686
require_once('remote/DesiredCapabilities.php');
8787
require_once('remote/WebDriverResponse.php');
88+
require_once('remote/RemoteTargetLocator.php');
8889

8990
require_once('remote/HttpCommandExecutor.php');
9091
require_once('remote/service/DriverCommandExecutor.php');

lib/chrome/ChromeDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function start(
2323
$desired_capabilities = DesiredCapabilities::chrome();
2424
}
2525
if ($service === null) {
26-
$service = ChromeDriverService::createDefaultService();
26+
$service = ChromeDriverService::createDefaultService();
2727
}
2828
$executor = new DriverCommandExecutor($service);
2929
$driver = new static();

lib/remote/RemoteTargetLocator.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
/**
17+
* Used to locate a given frame or window for RemoteWebDriver.
18+
*/
19+
class RemoteTargetLocator implements WebDriverTargetLocator {
20+
21+
protected $executor;
22+
protected $driver;
23+
24+
public function __construct($executor, $driver) {
25+
$this->executor = $executor;
26+
$this->driver = $driver;
27+
}
28+
29+
/**
30+
* Switch to the main document if the page contains iframes. Otherwise, switch
31+
* to the first frame on the page.
32+
*
33+
* @return WebDriver The driver focused on the top window or the first frame.
34+
*/
35+
public function defaultContent() {
36+
$params = array('id' => null);
37+
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params);
38+
39+
return $this->driver;
40+
}
41+
42+
/**
43+
* Switch to the iframe by its id or name.
44+
*
45+
* @param WebDriverElement|string $frame The WebDriverElement,
46+
the id or the name of the frame.
47+
* @return WebDriver The driver focused on the given frame.
48+
*/
49+
public function frame($frame) {
50+
if ($frame instanceof WebDriverElement) {
51+
$id = array('ELEMENT' => $frame->getID());
52+
} else {
53+
$id = (string)$frame;
54+
}
55+
56+
$params = array('id' => $id);
57+
$this->executor->execute(DriverCommand::SWITCH_TO_FRAME, $params);
58+
59+
return $this->driver;
60+
}
61+
62+
/**
63+
* Switch the focus to another window by its handle.
64+
*
65+
* @param string $handle The handle of the window to be focused on.
66+
* @return WebDriver Tge driver focused on the given window.
67+
* @see WebDriver::getWindowHandles
68+
*/
69+
public function window($handle) {
70+
$params = array('name' => (string)$handle);
71+
$this->executor->execute(DriverCommand::SWITCH_TO_WINDOW, $params);
72+
73+
return $this->driver;
74+
}
75+
76+
/**
77+
* Switch to the currently active modal dialog for this particular driver
78+
* instance.
79+
*
80+
* @return WebDriverAlert
81+
*/
82+
public function alert() {
83+
return new WebDriverAlert($this->executor);
84+
}
85+
86+
/**
87+
* Switches to the element that currently has focus within the document
88+
* currently "switched to", or the body element if this cannot be detected.
89+
*
90+
* @return RemoteWebElement
91+
*/
92+
public function activeElement() {
93+
$response = $this->driver->execute(DriverCommand::GET_ACTIVE_ELEMENT);
94+
$method = new RemoteExecuteMethod($this->driver);
95+
return new RemoteWebElement($method, $response['ELEMENT']);
96+
}
97+
}

lib/remote/RemoteWebDriver.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ public function navigate() {
348348
/**
349349
* Switch to a different window or frame.
350350
*
351-
* @return WebDriverTargetLocator
352-
* @see WebDriverTargetLocator
351+
* @return RemoteTargetLocator
352+
* @see RemoteTargetLocator
353353
*/
354354
public function switchTo() {
355-
return new WebDriverTargetLocator($this->getExecuteMethod(), $this);
355+
return new RemoteTargetLocator($this->getExecuteMethod(), $this);
356356
}
357357

358358
/**
@@ -401,16 +401,6 @@ public function action() {
401401
return new WebDriverActions($this);
402402
}
403403

404-
/**
405-
* Get the element on the page that currently has focus.
406-
*
407-
* @return RemoteWebElement
408-
*/
409-
public function getActiveElement() {
410-
$response = $this->execute(DriverCommand::GET_ACTIVE_ELEMENT);
411-
return $this->newElement($response['ELEMENT']);
412-
}
413-
414404
/**
415405
* Return the WebDriverElement with the given id.
416406
*

lib/support/events/EventFiringWebDriver.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,6 @@ public function getTouch() {
336336
}
337337
}
338338

339-
/**
340-
* Get the element on the page that currently has focus.
341-
*
342-
* @return WebDriverElement
343-
*/
344-
public function getActiveElement() {
345-
try {
346-
return $this->driver->getActiveElement();
347-
} catch (WebDriverException $exception) {
348-
$this->dispatchOnException($exception);
349-
}
350-
}
351-
352339
private function dispatchOnException($exception) {
353340
$this->dispatch('onException', $exception, $this);
354341
throw $exception;

0 commit comments

Comments
 (0)