/
WebDriverTouchActions.php
180 lines (156 loc) · 4.22 KB
/
WebDriverTouchActions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
namespace Facebook\WebDriver\Interactions;
use Facebook\WebDriver\Interactions\Touch\WebDriverDoubleTapAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverDownAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverFlickAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverFlickFromElementAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverLongPressAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverMoveAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverScrollAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverScrollFromElementAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverTapAction;
use Facebook\WebDriver\Interactions\Touch\WebDriverTouchScreen;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverElement;
use Facebook\WebDriver\WebDriverUpAction;
/**
* WebDriver action builder for touch events
*/
class WebDriverTouchActions extends WebDriverActions
{
/**
* @var WebDriverTouchScreen
*/
protected $touchScreen;
public function __construct(WebDriver $driver)
{
parent::__construct($driver);
$this->touchScreen = $driver->getTouch();
}
/**
* @param WebDriverElement $element
* @return WebDriverTouchActions
*/
public function tap(WebDriverElement $element)
{
$this->action->addAction(
new WebDriverTapAction($this->touchScreen, $element)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function down($x, $y)
{
$this->action->addAction(
new WebDriverDownAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function up($x, $y)
{
$this->action->addAction(
new WebDriverUpAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function move($x, $y)
{
$this->action->addAction(
new WebDriverMoveAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function scroll($x, $y)
{
$this->action->addAction(
new WebDriverScrollAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param WebDriverElement $element
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function scrollFromElement(WebDriverElement $element, $x, $y)
{
$this->action->addAction(
new WebDriverScrollFromElementAction($this->touchScreen, $element, $x, $y)
);
return $this;
}
/**
* @param WebDriverElement $element
* @return WebDriverTouchActions
*/
public function doubleTap(WebDriverElement $element)
{
$this->action->addAction(
new WebDriverDoubleTapAction($this->touchScreen, $element)
);
return $this;
}
/**
* @param WebDriverElement $element
* @return WebDriverTouchActions
*/
public function longPress(WebDriverElement $element)
{
$this->action->addAction(
new WebDriverLongPressAction($this->touchScreen, $element)
);
return $this;
}
/**
* @param int $x
* @param int $y
* @return WebDriverTouchActions
*/
public function flick($x, $y)
{
$this->action->addAction(
new WebDriverFlickAction($this->touchScreen, $x, $y)
);
return $this;
}
/**
* @param WebDriverElement $element
* @param int $x
* @param int $y
* @param int $speed
* @return WebDriverTouchActions
*/
public function flickFromElement(WebDriverElement $element, $x, $y, $speed)
{
$this->action->addAction(
new WebDriverFlickFromElementAction(
$this->touchScreen,
$element,
$x,
$y,
$speed
)
);
return $this;
}
}