|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Openbuildings\Spiderling; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Base class for Spiderling driver. |
|
7
|
|
|
* |
|
8
|
|
|
* @package Openbuildings\Spiderling |
|
9
|
|
|
* @author Ivan Kerin |
|
10
|
|
|
* @copyright (c) 2013 OpenBuildings Ltd. |
|
11
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
|
12
|
|
|
*/ |
|
13
|
|
|
abstract class Driver { |
|
14
|
|
|
|
|
15
|
|
|
public $page = NULL; |
|
16
|
|
|
|
|
17
|
|
|
public $name = NULL; |
|
18
|
|
|
|
|
19
|
|
|
public $default_wait_time = 3000; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Clear session stuff / cookies created by the current page |
|
23
|
|
|
* @return $this |
|
24
|
|
|
*/ |
|
25
|
1 |
|
public function clear() |
|
26
|
|
|
{ |
|
27
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Return an array of HTML fragments that match a given XPath query |
|
32
|
|
|
* @param string $id |
|
33
|
|
|
* @return array |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function all($id) |
|
36
|
|
|
{ |
|
37
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Return an the id of the html elemenet |
|
42
|
|
|
* @throws Exception_Notfound If element not found |
|
43
|
|
|
* @param string $id |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function find($id) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Return the HTML content of the current page or set it manually |
|
53
|
|
|
* @param string $content |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function content($content = NULL) |
|
57
|
|
|
{ |
|
58
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Return the tag name of a HTML fragemnt, specified by id |
|
63
|
|
|
* If multiple tags match - return the first one. |
|
64
|
|
|
* @param string $id |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function tag_name($id) |
|
68
|
|
|
{ |
|
69
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Return the tag attribute of an HTML fragment, spesified by id |
|
74
|
|
|
* If multiple tags match - return the first one. |
|
75
|
|
|
* @param string $id |
|
76
|
|
|
* @param string $name |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function attribute($id, $name) |
|
80
|
|
|
{ |
|
81
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Return the HTML fragment, spesified by id |
|
86
|
|
|
* If multiple tags match - return the first one. |
|
87
|
|
|
* @param string $id |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function html($id) |
|
91
|
|
|
{ |
|
92
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Return the plain text of an HTML fragment, spesified by id |
|
97
|
|
|
* If multiple tags match - return the first one. |
|
98
|
|
|
* @param string $id |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
1 |
|
public function text($id) |
|
102
|
|
|
{ |
|
103
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Retrun the value of an HTML fragment of a form input, spesified by id |
|
108
|
|
|
* If multiple tags match - return the first one. |
|
109
|
|
|
* The value is specific for diferrent for each input type. |
|
110
|
|
|
* - input -> value |
|
111
|
|
|
* - textarea -> content |
|
112
|
|
|
* - checkbox -> checked |
|
113
|
|
|
* - radios -> checked |
|
114
|
|
|
* - select -> selected option |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $id |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
1 |
|
public function value($id) |
|
120
|
|
|
{ |
|
121
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Return the visibility of an HTML fragment, spesified by id |
|
126
|
|
|
* If multiple tags match - return the first one. |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $id |
|
129
|
|
|
* @return string |
|
130
|
|
|
*/ |
|
131
|
1 |
|
public function is_visible($id) |
|
132
|
|
|
{ |
|
133
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Return if the option is selected or not, spesified by id |
|
138
|
|
|
* If multiple tags match - return the first one. |
|
139
|
|
|
* |
|
140
|
|
|
* @param string $id |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
1 |
|
public function is_selected($id) |
|
144
|
|
|
{ |
|
145
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Return if the input (checkbox/radio) is checked or not, spesified by id |
|
150
|
|
|
* If multiple tags match - return the first one. |
|
151
|
|
|
* |
|
152
|
|
|
* @param string $id |
|
153
|
|
|
* @return string |
|
154
|
|
|
*/ |
|
155
|
1 |
|
public function is_checked($id) |
|
156
|
|
|
{ |
|
157
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
158
|
|
|
} |
|
159
|
|
|
/** |
|
160
|
|
|
* Set the value for a form input tag. |
|
161
|
|
|
* If multiple tags match - use the first one. |
|
162
|
|
|
* |
|
163
|
|
|
* @param string $id |
|
164
|
|
|
* @param mixed $value value |
|
165
|
|
|
*/ |
|
166
|
1 |
|
public function set($id, $value) |
|
167
|
|
|
{ |
|
168
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Set an HTML option tag as selected or remove selection for a given XPath query. |
|
173
|
|
|
* If multiple tags match - use the first one. |
|
174
|
|
|
* |
|
175
|
|
|
* @param string $id |
|
176
|
|
|
* @param boolean $value |
|
177
|
|
|
* @return $this |
|
178
|
|
|
*/ |
|
179
|
1 |
|
public function select_option($id, $value) |
|
180
|
|
|
{ |
|
181
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Initiate a click on a given element. |
|
186
|
|
|
* If multiple tags match - use the first one. |
|
187
|
|
|
* You can click on anchor and submit buttons. |
|
188
|
|
|
* |
|
189
|
|
|
* @param string $id |
|
190
|
|
|
* @return $this |
|
191
|
|
|
*/ |
|
192
|
1 |
|
public function click($id) |
|
193
|
|
|
{ |
|
194
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Go to a specified url |
|
199
|
|
|
* @param string $uri |
|
200
|
|
|
* @param array $query |
|
201
|
|
|
* @return $this |
|
202
|
|
|
*/ |
|
203
|
1 |
|
public function visit($uri, array $query = array()) |
|
204
|
|
|
{ |
|
205
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Get the current url without domain |
|
210
|
|
|
* @return string |
|
211
|
|
|
*/ |
|
212
|
1 |
|
public function current_path() |
|
213
|
|
|
{ |
|
214
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Get the current url with domain |
|
219
|
|
|
* @return string |
|
220
|
|
|
*/ |
|
221
|
1 |
|
public function current_url() |
|
222
|
|
|
{ |
|
223
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Confirm or cancel for the next confirmation dialog |
|
228
|
|
|
* @param bool $confirm |
|
229
|
|
|
*/ |
|
230
|
1 |
|
public function confirm($confirm) |
|
|
|
|
|
|
231
|
|
|
{ |
|
232
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Get the text of the currently displayed alert / confirm /prompt dialog |
|
237
|
|
|
* @param bool $confirm |
|
|
|
|
|
|
238
|
|
|
*/ |
|
239
|
1 |
|
public function alert_text() |
|
240
|
|
|
{ |
|
241
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Return The root node |
|
246
|
|
|
* @return Node |
|
247
|
|
|
*/ |
|
248
|
1 |
|
public function is_page_active() |
|
249
|
|
|
{ |
|
250
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Move the mouse to a certain element |
|
255
|
|
|
*/ |
|
256
|
1 |
|
public function move_to($id = NULL, $x = NULL, $y = NULL) |
|
|
|
|
|
|
257
|
|
|
{ |
|
258
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Take a screenshot ant place it in the given file |
|
263
|
|
|
* @param string $file |
|
264
|
|
|
*/ |
|
265
|
1 |
|
public function screenshot($file) |
|
266
|
|
|
{ |
|
267
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* execute Javascript |
|
272
|
|
|
*/ |
|
273
|
1 |
|
public function execute($id, $script) |
|
274
|
|
|
{ |
|
275
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Get the current browser user agent |
|
280
|
|
|
*/ |
|
281
|
1 |
|
public function user_agent() |
|
282
|
|
|
{ |
|
283
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* Manually set a cookie |
|
288
|
|
|
* |
|
289
|
|
|
* @param string $name |
|
290
|
|
|
* @param string $value |
|
291
|
|
|
* @param integer $expires |
|
|
|
|
|
|
292
|
|
|
*/ |
|
293
|
1 |
|
public function cookie($name, $value, array $parameters = array()) |
|
294
|
|
|
{ |
|
295
|
1 |
|
throw new Exception_Notimplemented(__FUNCTION__, $this); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Return all the javascript errors on the page |
|
300
|
|
|
* @return Node |
|
301
|
|
|
*/ |
|
302
|
1 |
|
public function javascript_errors() |
|
303
|
|
|
{ |
|
304
|
1 |
|
return array(); |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Return all the javascript console messages on the page |
|
309
|
|
|
* @return Node |
|
310
|
|
|
*/ |
|
311
|
1 |
|
public function javascript_messages() |
|
312
|
|
|
{ |
|
313
|
1 |
|
return array(); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* Return The root node |
|
318
|
|
|
* @return Node |
|
319
|
|
|
*/ |
|
320
|
9 |
|
public function page() |
|
321
|
|
|
{ |
|
322
|
9 |
|
if ( ! $this->page) |
|
323
|
|
|
{ |
|
324
|
9 |
|
$this->page = new Page($this); |
|
325
|
|
|
} |
|
326
|
9 |
|
return $this->page; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Extract implicit query from URI |
|
331
|
|
|
* |
|
332
|
|
|
* @return array |
|
333
|
|
|
*/ |
|
334
|
|
|
public static function extract_query_from_uri($uri) |
|
335
|
|
|
{ |
|
336
|
|
|
$uri_query_str = parse_url($uri, PHP_URL_QUERY); |
|
337
|
|
|
|
|
338
|
|
|
if ( ! $uri_query_str) |
|
|
|
|
|
|
339
|
|
|
{ |
|
340
|
|
|
return array(); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
parse_str($uri_query_str, $uri_query); |
|
344
|
|
|
|
|
345
|
|
|
return $uri_query; |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
} |
|
349
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.