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

Commit f7777d1

Browse files
committed
Merge pull request #91 from ashleydw/master
Implement touch events and various other protocols (orientation, logging, equals, and active element)
2 parents 3121f59 + 12834db commit f7777d1

23 files changed

+881
-2
lines changed

lib/WebDriverCommandExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
interface WebDriverCommandExecutor {
2020

2121
// $command and $params will be merged to an command object in the future.
22-
public function execute($command, array $params);
22+
public function execute($command, array $params = array());
2323
}

lib/WebDriverOptions.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,26 @@ public function timeouts() {
131131
public function window() {
132132
return new WebDriverWindow($this->executor);
133133
}
134+
135+
/**
136+
* Get the log for a given log type. Log buffer is reset after each request.
137+
*
138+
* @param The log type (https://code.google.com/p/selenium/wiki/JsonWireProtocol#Log_Type)
139+
* @return array The list of log entries.
140+
*/
141+
public function getLog($logType) {
142+
return $this->executor->execute('getLog', array(
143+
'type' => $logType
144+
));
145+
}
146+
147+
/**
148+
* Get available log types.
149+
*
150+
* @return array The list of available log types (https://code.google.com/p/selenium/wiki/JsonWireProtocol#Log_Type)
151+
*/
152+
public function getAvailableLogTypes() {
153+
return $this->executor->execute('getAvailableLogTypes');
154+
}
155+
134156
}

lib/WebDriverWindow.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,34 @@ public function setPosition(WebDriverPoint $position) {
106106
$this->executor->execute('setWindowPosition', $params);
107107
return $this;
108108
}
109+
110+
/**
111+
* Get the current browser orientation.
112+
*
113+
* @return string Either LANDSCAPE|PORTRAIT
114+
*/
115+
public function getScreenOrientation() {
116+
return $this->executor->execute('getScreenOrientation');
117+
}
118+
119+
120+
/**
121+
* Set the browser orientation. The orientation should either LANDSCAPE|PORTRAIT
122+
*
123+
* @param string $orientation
124+
* @return WebDriverWindow The instance.
125+
* @throws IndexOutOfBoundsWebDriverError
126+
*/
127+
public function setScreenOrientation($orientation) {
128+
129+
$orientation = strtoupper($orientation);
130+
if (!in_array($orientation, array('PORTRAIT', 'LANDSCAPE')))
131+
throw new IndexOutOfBoundsWebDriverError("Orientation must be either PORTRAIT, or LANDSCAPE");
132+
133+
$this->executor->execute('setScreenOrientation', array('orientation' => $orientation));
134+
135+
return $this;
136+
137+
}
138+
109139
}

lib/__init__.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,19 @@
7070
require_once('support/events/EventFiringWebDriverNavigation.php');
7171
require_once('WebDriverDispatcher.php');
7272
require_once('support/events/EventFiringWebElement.php');
73+
74+
// touch
75+
require_once('interactions/WebDriverTouchScreen.php');
76+
require_once('remote/RemoteTouch.php');
77+
require_once('interactions/WebDriverTouchActions.php');
78+
require_once('interactions/touch/WebDriverTouchAction.php');
79+
require_once('interactions/touch/WebDriverDoubleTapAction.php');
80+
require_once('interactions/touch/WebDriverDownAction.php');
81+
require_once('interactions/touch/WebDriverFlickAction.php');
82+
require_once('interactions/touch/WebDriverFlickFromElementAction.php');
83+
require_once('interactions/touch/WebDriverLongPressAction.php');
84+
require_once('interactions/touch/WebDriverMoveAction.php');
85+
require_once('interactions/touch/WebDriverScrollAction.php');
86+
require_once('interactions/touch/WebDriverScrollFromElementAction.php');
87+
require_once('interactions/touch/WebDriverTapAction.php');
88+
require_once('interactions/touch/WebDriverUpAction.php');
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
* WebDriver action builder for touch events
18+
*/
19+
class WebDriverTouchActions {
20+
21+
/**
22+
* @var WebDriverTouchScreen
23+
*/
24+
protected $touchScreen;
25+
26+
/**
27+
* @var WebDriver
28+
*/
29+
protected $driver;
30+
31+
/**
32+
* @var WebDriverKeyboard
33+
*/
34+
protected $keyboard;
35+
36+
/**
37+
* @var WebDriverMouse
38+
*/
39+
protected $mouse;
40+
41+
/**
42+
* @var WebDriverCompositeAction
43+
*/
44+
protected $action;
45+
46+
public function __construct(WebDriver $driver) {
47+
$this->driver = $driver;
48+
$this->keyboard = $driver->getKeyboard();
49+
$this->mouse = $driver->getMouse();
50+
$this->touchScreen = $driver->getTouch();
51+
$this->action = new WebDriverCompositeAction();
52+
}
53+
54+
public function tap(WebDriverElement $element) {
55+
$this->action->addAction(
56+
new WebDriverTapAction($this->touchScreen, $element)
57+
);
58+
return $this;
59+
}
60+
61+
public function down($x, $y) {
62+
$this->action->addAction(
63+
new WebDriverDownAction($this->touchScreen, $x, $y)
64+
);
65+
return $this;
66+
}
67+
68+
public function up($x, $y) {
69+
$this->action->addAction(
70+
new WebDriverUpAction($this->touchScreen, $x, $y)
71+
);
72+
return $this;
73+
}
74+
75+
public function move($x, $y) {
76+
$this->action->addAction(
77+
new WebDriverMoveAction($this->touchScreen, $x, $y)
78+
);
79+
return $this;
80+
}
81+
82+
public function scroll($x, $y) {
83+
$this->action->addAction(
84+
new WebDriverScrollAction($this->touchScreen, $x, $y)
85+
);
86+
return $this;
87+
}
88+
89+
public function scrollFromElement(WebDriverElement $element, $x, $y) {
90+
$this->action->addAction(
91+
new WebDriverScrollFromElementAction($this->touchScreen, $element, $x, $y)
92+
);
93+
return $this;
94+
}
95+
96+
public function doubleTap(WebDriverElement $element) {
97+
$this->action->addAction(
98+
new WebDriverDoubleTapAction($this->touchScreen, $element)
99+
);
100+
return $this;
101+
}
102+
103+
public function longPress(WebDriverElement $element) {
104+
$this->action->addAction(
105+
new WebDriverLongPressAction($this->touchScreen, $element)
106+
);
107+
return $this;
108+
}
109+
110+
public function flick($x, $y) {
111+
$this->action->addAction(
112+
new WebDriverFlickAction($this->touchScreen, $x, $y)
113+
);
114+
return $this;
115+
}
116+
117+
public function flickFromElement(WebDriverElement $element, $x, $y, $speed) {
118+
$this->action->addAction(
119+
new WebDriverFlickFromElementAction($this->touchScreen, $element, $x, $y, $speed)
120+
);
121+
return $this;
122+
}
123+
124+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 representing touch screen operations.
18+
*/
19+
interface WebDriverTouchScreen {
20+
21+
/**
22+
* Single tap on the touch enabled device.
23+
*
24+
* @param WebDriverElement $element
25+
* @return $this
26+
*/
27+
public function tap(WebDriverElement $element);
28+
29+
/**
30+
* Double tap on the touch screen using finger motion events.
31+
*
32+
* @param WebDriverElement $element
33+
* @return $this
34+
*/
35+
public function doubleTap(WebDriverElement $element);
36+
37+
/**
38+
* Finger down on the screen.
39+
*
40+
* @param $x
41+
* @param $y
42+
* @return $this
43+
*/
44+
public function down($x, $y);
45+
46+
/**
47+
* Flick on the touch screen using finger motion events. Use this flick command if you don't care where the flick starts on the screen.
48+
*
49+
* @param int $xpeed
50+
* @param int $yspeed
51+
* @return $this
52+
*/
53+
public function flick($xspeed, $yspeed);
54+
55+
/**
56+
* Flick on the touch screen using finger motion events. This flickcommand starts at a particular screen location.
57+
*
58+
* @param WebDriverElement $element
59+
* @param int $xoffset
60+
* @param int $yoffset
61+
* @param int $speed
62+
* @return $this
63+
*/
64+
public function flickFromElement(WebDriverElement $element, $xoffset, $yoffset, $speed);
65+
66+
/**
67+
* Long press on the touch screen using finger motion events.
68+
*
69+
* @return $this
70+
*/
71+
public function longPress(WebDriverElement $element);
72+
73+
/**
74+
* Finger move on the screen.
75+
*
76+
* @param int $x
77+
* @param int $y
78+
* @return $this
79+
*/
80+
public function move($x, $y);
81+
82+
83+
/**
84+
* Scroll on the touch screen using finger based motion events. Use this command if you don't care where the scroll starts on the screen.
85+
*
86+
* @param int $xoffset
87+
* @param int $yoffset
88+
* @return $this
89+
*/
90+
public function scroll($xoffset, $yoffset);
91+
92+
/**
93+
* Scroll on the touch screen using finger based motion events. Use this command to start scrolling at a particular screen location.
94+
*
95+
* @param WebDriverElement $element
96+
* @param int $xoffset
97+
* @param int $yoffset
98+
* @return $this
99+
*/
100+
public function scrollFromElement(WebDriverElement $element, $xoffset, $yoffset);
101+
102+
/**
103+
* Finger up on the screen.
104+
*
105+
* @param int $x
106+
* @param int $y
107+
* @return $this
108+
*/
109+
public function up($x, $y);
110+
111+
}
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+
class WebDriverDoubleTapAction
17+
extends WebDriverTouchAction
18+
implements WebDriverAction {
19+
20+
public function perform() {
21+
$this->touchScreen->doubleTap($this->locationProvider);
22+
}
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
class WebDriverDownAction
17+
extends WebDriverTouchAction
18+
implements WebDriverAction {
19+
20+
private $x;
21+
private $y;
22+
23+
public function __construct(WebDriverTouchScreen $touch_screen, $x, $y) {
24+
$this->x = $x;
25+
$this->y = $y;
26+
parent::_construct($touch_screen);
27+
}
28+
29+
public function perform() {
30+
$this->touchScreen->down($this->x, $this->y);
31+
}
32+
}

0 commit comments

Comments
 (0)