Skip to content

Commit 438ee2e

Browse files
committed
touch chaining
1 parent 66fcc48 commit 438ee2e

File tree

2 files changed

+101
-3
lines changed

2 files changed

+101
-3
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
// Copyright 2011-present Element 34
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+
include_once('WebDriverActionChains.php');
17+
18+
class PHPWebDriver_WebDriverTouchActions extends PHPWebDriver_WebDriverActionChains {
19+
20+
public function __construct($session) {
21+
parent::__construct($session);
22+
}
23+
24+
public function single_tap($element, $curl_opts = array()) {
25+
$this->actions[] = "return \$this->session->touch()->click(array('element' => '" . $element->getID() . "'), " . unwind_associated_array($curl_opts) . ");";
26+
return $this;
27+
}
28+
29+
public function down($x, $y, $curl_opts = array()) {
30+
$this->actions[] = "return \$this->session->touch()->down(array('x' => " . $x . ", 'y' => " . $y . "), " . unwind_associated_array($curl_opts) . ");";
31+
return $this;
32+
}
33+
34+
public function move($x, $y, $curl_opts = array()) {
35+
$this->actions[] = "return \$this->session->touch()->move(array('x' => " . $x . ", 'y' => " . $y . "), " . unwind_associated_array($curl_opts) . ");";
36+
return $this;
37+
}
38+
39+
public function up($x, $y, $curl_opts = array()) {
40+
$this->actions[] = "return \$this->session->touch()->up(array('x' => " . $x . ", 'y' => " . $y . "), " . unwind_associated_array($curl_opts) . ");";
41+
return $this;
42+
}
43+
44+
public function element_scroll($element, $xoffset, $yoffset, $curl_opts = array()) {
45+
$this->actions[] = "return \$this->session->touch()->scroll(array('element' => '" . $element->getID() . "', 'xoffset' => " . $xoffset . ", 'yoffset' => " . $yoffset . "), " . unwind_associated_array($curl_opts) . ");";
46+
return $this;
47+
}
48+
49+
public function scroll($xoffset, $yoffset, $curl_opts = array()) {
50+
$this->actions[] = "return \$this->session->touch()->scroll(array('xoffset' => " . $xoffset . ", 'yoffset' => " . $yoffset . "), " . unwind_associated_array($curl_opts) . ");";
51+
return $this;
52+
}
53+
54+
public function double_tap($element, $curl_opts = array()) {
55+
$this->actions[] = "return \$this->session->touch()->doubleclick(array('element' => '" . $element->getID() . "'), " . unwind_associated_array($curl_opts) . ");";
56+
return $this;
57+
}
58+
59+
public function long_tap($element, $curl_opts = array()) {
60+
$this->actions[] = "return \$this->session->touch()->longclick(array('element' => '" . $element->getID() . "'), " . unwind_associated_array($curl_opts) . ");";
61+
return $this;
62+
}
63+
64+
public function flick($xspeed, $yspeed, $curl_opts = array()) {
65+
$this->actions[] = "return \$this->session->touch()->flick(array('xspeed' => " . $xspeed . ", 'yspeed' => " . $yspeed . "), " . unwind_associated_array($curl_opts) . ");";
66+
return $this;
67+
}
68+
69+
public function element_flick($element, $xoffset, $yoffset, $speed, $curl_opts = array()) {
70+
$this->actions[] = "return \$this->session->touch()->flick(array('element' => '" . $element->getID() . "', 'xoffset' => " . $xoffset . ", 'yoffset' => " . $yoffset . ", 'speed' => " . $speed . "), " . unwind_associated_array($curl_opts) . ");";
71+
return $this;
72+
}
73+
}
74+

test/browsers/AndroidTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
require_once(dirname(__FILE__) . '/../../PHPWebDriver/WebDriver.php');
1919
require_once(dirname(__FILE__) . '/../../PHPWebDriver/WebDriverWait.php');
2020
require_once(dirname(__FILE__) . '/../../PHPWebDriver/WebDriverSession.php');
21+
require_once(dirname(__FILE__) . '/../../PHPWebDriver/WebDriverTouchActions.php');
2122
require_once(dirname(__FILE__) . '/../sauce/pages/login.php');
2223

2324

@@ -78,14 +79,14 @@ public function testAndroidElementScroll() {
7879
$this->session = self::$driver->session("android");
7980
$this->session->open("http://www.illicitonion.com/selenium-web/longContentPage.html");
8081
$e = $this->session->element("id", "imagestart");
81-
$this->session->touch()->down(array('element' => $e->getID(), 'x' => 100, 'y' => 0));
82+
$this->session->touch()->scroll(array('element' => $e->getID(), 'xoffset' => 100, 'yoffset' => 0));
8283
}
8384

8485
/**
8586
* @group android
8687
* @group scroll
8788
*/
88-
public function testAndroidScroll()) {
89+
public function testAndroidScroll() {
8990
$this->session = self::$driver->session("android");
9091
$this->session->open("http://www.illicitonion.com/selenium-web/longContentPage.html");
9192

@@ -95,7 +96,7 @@ public function testAndroidScroll()) {
9596
$e = $this->session->element("id", "link4");
9697
$bottom = $e->location();
9798

98-
$this->session->touch()->down(array('x' => $top['x'] + $bottom['x'], 'y' => 0));
99+
$this->session->touch()->scroll(array('xoffset' => $top['x'] + $bottom['x'], 'yoffset' => 0));
99100
}
100101

101102
/**
@@ -163,4 +164,27 @@ public function testAndroidFlick() {
163164
$this->assertTrue($after['x'] < 1500);
164165
}
165166

167+
/**
168+
* @group android
169+
* @group chains
170+
*/
171+
public function testAndroidChains() {
172+
$this->session = self::$driver->session("android");
173+
$this->session->open("http://www.illicitonion.com/selenium-web/clicks.html");
174+
175+
$e = $this->session->element("id", "normal");
176+
$a = new \PHPWebDriver_WebDriverTouchActions($this->session);
177+
$a = $a->single_tap($e);
178+
$a = $a->down(1000, 50);
179+
$a = $a->move(-1000, 0);
180+
$a = $a->up(-2000, 50);
181+
$a = $a->element_scroll($e, -2000, 50);
182+
$a = $a->scroll(-2000, 50);
183+
$a = $a->double_tap($e);
184+
$a = $a->long_tap($e);
185+
$a = $a->flick(40, 400);
186+
$a = $a->element_flick($e, 40, 400, \PHPWebDriver_WebDriverSession::FLICK_SPEED_NORMAL);
187+
$a->perform();
188+
}
189+
166190
}

0 commit comments

Comments
 (0)