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

Commit 8ccef05

Browse files
author
whhone
committed
refactor commandexecutor
1 parent 25c3d52 commit 8ccef05

8 files changed

+330
-20
lines changed

lib/WebDriver.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* The interface for WebDriver.
1818
*/
19-
interface WebDriver {
19+
interface WebDriver extends WebDriverSearchContext {
2020

2121
/**
2222
* Close the current window.
@@ -28,23 +28,23 @@ public function close();
2828
/**
2929
* Find the first WebDriverElement using the given mechanism.
3030
*
31-
* @param WebDriverBy $by
31+
* @param WebDriverBy $locator
3232
* @return WebDriverElement NoSuchElementWebDriverError is thrown in
33-
* WebDriverCommandExecutor if no element is found.
33+
* HttpCommandExecutor if no element is found.
3434
* @see WebDriverBy
3535
*/
36-
public function findElement(WebDriverBy $by);
36+
public function findElement(WebDriverBy $locator);
3737

3838
/**
3939
* Find all WebDriverElements within the current page using the given
4040
* mechanism.
4141
*
42-
* @param WebDriverBy $by
42+
* @param WebDriverBy $locator
4343
* @return array A list of all WebDriverElements, or an empty array if
4444
* nothing matches
4545
* @see WebDriverBy
4646
*/
47-
public function findElements(WebDriverBy $by);
47+
public function findElements(WebDriverBy $locator);
4848

4949
/**
5050
* Load a new web page in the current browser window.

lib/WebDriverCommandExecutor.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
* Interface for all command executor.
18+
*/
19+
interface WebDriverCommandExecutor {
20+
21+
// $command and $params will be merged to an command object in the future.
22+
public function execute($command, array $params);
23+
}

lib/WebDriverElement.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Interface for an HTML element in the WebDriver framework.
1818
*/
19-
interface WebDriverElement {
19+
interface WebDriverElement extends WebDriverSearchContext {
2020

2121
/**
2222
* If this element is a TEXTAREA or text INPUT element, this will clear the
@@ -37,22 +37,22 @@ public function click();
3737
* Find the first WebDriverElement within this element using the given
3838
* mechanism.
3939
*
40-
* @param WebDriverBy $by
40+
* @param WebDriverBy $locator
4141
* @return WebDriverElement NoSuchElementWebDriverError is thrown in
42-
* WebDriverCommandExecutor if no element is found.
42+
* HttpCommandExecutor if no element is found.
4343
* @see WebDriverBy
4444
*/
45-
public function findElement(WebDriverBy $by);
45+
public function findElement(WebDriverBy $locator);
4646

4747
/**
4848
* Find all WebDriverElements within this element using the given mechanism.
4949
*
50-
* @param WebDriverBy $by
50+
* @param WebDriverBy $locator
5151
* @return array A list of all WebDriverElements, or an empty array if
5252
* nothing matches
5353
* @see WebDriverBy
5454
*/
55-
public function findElements(WebDriverBy $by);
55+
public function findElements(WebDriverBy $locator);
5656

5757
/**
5858
* Get the value of a the given attribute of the element.

lib/WebDriverSearchContext.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
* The interface for WebDriver and WebDriverElement which is able to search for
18+
* WebDriverElement inside.
19+
*/
20+
interface WebDriverSearchContext {
21+
22+
/**
23+
* Find the first WebDriverElement within this element using the given
24+
* mechanism.
25+
*
26+
* @param WebDriverBy $locator
27+
* @return WebDriverElement NoSuchElementWebDriverError is thrown in
28+
* HttpCommandExecutor if no element is found.
29+
* @see WebDriverBy
30+
*/
31+
public function findElement(WebDriverBy $locator);
32+
33+
/**
34+
* Find all WebDriverElements within this element using the given mechanism.
35+
*
36+
* @param WebDriverBy $locator
37+
* @return array A list of all WebDriverElements, or an empty array if
38+
* nothing matches
39+
* @see WebDriverBy
40+
*/
41+
public function findElements(WebDriverBy $locator);
42+
}

lib/__init__.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
// interface
17+
require_once('WebDriverSearchContext.php');
1618
require_once('WebDriver.php');
19+
require_once('WebDriverElement.php');
20+
require_once('WebDriverCommandExecutor.php');
21+
22+
// class
1723
require_once('WebDriverAction.php');
1824
require_once('WebDriverAlert.php');
1925
require_once('WebDriverBy.php');
2026
require_once('WebDriverDimension.php');
21-
require_once('WebDriverElement.php');
2227
require_once('WebDriverExceptions.php');
2328
require_once('WebDriverExpectedCondition.php');
2429
require_once('WebDriverHasInputDevices.php');
@@ -49,4 +54,4 @@
4954
require_once('remote/RemoteWebElement.php');
5055
require_once('remote/WebDriverBrowserType.php');
5156
require_once('remote/WebDriverCapabilityType.php');
52-
require_once('remote/WebDriverCommandExecutor.php');
57+
require_once('remote/HttpCommandExecutor.php');

0 commit comments

Comments
 (0)