line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::WWW::WebKit; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Test::WWW::WebKit - Perl extension for using an embedding WebKit engine for tests |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Test::WWW::WebKit; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $webkit = Test::WWW::WebKit->new(xvfb => 1); |
12
|
|
|
|
|
|
|
$webkit->init; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$webkit->open_ok("http://www.google.com"); |
15
|
|
|
|
|
|
|
$webkit->type_ok("q", "hello world"); |
16
|
|
|
|
|
|
|
$webkit->click_ok("btnG"); |
17
|
|
|
|
|
|
|
$webkit->wait_for_page_to_load_ok(5000); |
18
|
|
|
|
|
|
|
$webkit->title_is("foo"); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Test::WWW::WebKit is a drop-in replacement for Test::WWW::Selenium using Gtk3::WebKit as browser instead of relying on an external Java server and an installed browser. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 EXPORT |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
None by default. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
34338
|
use 5.10.0; |
|
1
|
|
|
|
|
5
|
|
31
|
1
|
|
|
1
|
|
489
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
extends 'WWW::WebKit' => { -version => 0.06 }; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Glib qw(TRUE FALSE); |
36
|
|
|
|
|
|
|
use Time::HiRes qw(time usleep); |
37
|
|
|
|
|
|
|
use Test::More; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub open_ok { |
42
|
|
|
|
|
|
|
my ($self, $url) = @_; |
43
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->open($url); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
ok(1, "open_ok($url)"); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub refresh_ok { |
51
|
|
|
|
|
|
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->refresh; |
55
|
|
|
|
|
|
|
ok(1, "refresh_ok()"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub go_back_ok { |
59
|
|
|
|
|
|
|
my ($self) = @_; |
60
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->go_back; |
63
|
|
|
|
|
|
|
ok(1, "go_back_ok()"); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub select_ok { |
67
|
|
|
|
|
|
|
my ($self, $select, $option) = @_; |
68
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
ok($self->select($select, $option), "select_ok($select, $option)"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub click_ok { |
74
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
75
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
ok($self->click($locator), "click_ok($locator)"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub wait_for_page_to_load_ok { |
81
|
|
|
|
|
|
|
my ($self, $timeout) = @_; |
82
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$self->wait_for_page_to_load($timeout); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub wait_for_element_present_ok { |
88
|
|
|
|
|
|
|
my ($self, $locator, $timeout, $description) = @_; |
89
|
|
|
|
|
|
|
$description //= ''; |
90
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$timeout ||= $self->default_timeout; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
ok($self->wait_for_element_present($locator, $timeout), "wait_for_element_present_ok($locator, $timeout, $description)"); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub wait_for_element_to_disappear_ok { |
98
|
|
|
|
|
|
|
my ($self, $locator, $timeout, $description) = @_; |
99
|
|
|
|
|
|
|
$description //= ''; |
100
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$timeout ||= $self->default_timeout; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
ok($self->wait_for_element_to_disappear($locator, $timeout), "wait_for_element_to_disappear_ok($locator, $timeout, $description)"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub wait_for_condition_ok { |
108
|
|
|
|
|
|
|
my ($self, $condition, $timeout, $description) = @_; |
109
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
ok($self->wait_for_condition($condition, $timeout), $description); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub wait_for_pending_requests_ok { |
115
|
|
|
|
|
|
|
my ($self, $timeout, $description) = @_; |
116
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
ok($self->wait_for_pending_requests($timeout), $description); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub is_element_present_ok { |
122
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
123
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $result = $self->is_element_present($locator); |
126
|
|
|
|
|
|
|
my $retval = ok($result, "is_element_present_ok($locator)") |
127
|
|
|
|
|
|
|
or diag "# $@\n"; |
128
|
|
|
|
|
|
|
return $retval; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub type_ok { |
132
|
|
|
|
|
|
|
my ($self, $locator, $text) = @_; |
133
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
ok(eval { $self->type($locator, $text) }, "type_ok($locator, $text)"); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub type_keys_ok { |
139
|
|
|
|
|
|
|
my ($self, $locator, $text) = @_; |
140
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
ok(eval { $self->type_keys($locator, $text) }, "type_keys_ok($locator, $text)"); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub control_key_down_ok { |
146
|
|
|
|
|
|
|
my ($self) = @_; |
147
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$self->control_key_down; |
150
|
|
|
|
|
|
|
ok(1, "control_key_down_ok()"); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub control_key_up_ok { |
154
|
|
|
|
|
|
|
my ($self) = @_; |
155
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$self->control_key_up; |
158
|
|
|
|
|
|
|
ok(1, "control_key_up_ok()"); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub is_ordered_ok { |
162
|
|
|
|
|
|
|
my ($self, $first, $second) = @_; |
163
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
ok($self->is_ordered($first, $second), "is_ordered_ok($first, $second)"); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub mouse_over_ok { |
169
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
170
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
ok($self->mouse_over($locator), "mouse_over_ok($locator)"); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub mouse_down_ok { |
176
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
177
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
ok($self->mouse_down($locator), "mouse_down_ok($locator)"); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub fire_event_ok { |
183
|
|
|
|
|
|
|
my ($self, $locator, $event_type) = @_; |
184
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
ok($self->fire_event($locator, $event_type), "fire_event_ok($locator, $event_type)"); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub text_is { |
190
|
|
|
|
|
|
|
my ($self, $locator, $text, $description) = @_; |
191
|
|
|
|
|
|
|
$description //= ''; |
192
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
is($self->get_text($locator), $text, "text_is($locator, $text, $description)"); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub text_like { |
198
|
|
|
|
|
|
|
my ($self, $locator, $text) = @_; |
199
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
like($self->get_text($locator), $text); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub body_text_like { |
205
|
|
|
|
|
|
|
my ($self, $text) = @_; |
206
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
like($self->get_body_text(), $text, "body_text_like($text)"); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub value_is { |
212
|
|
|
|
|
|
|
my ($self, $locator, $value) = @_; |
213
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
is($self->get_value($locator), $value, "value_is($locator, $value)"); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub title_like { |
219
|
|
|
|
|
|
|
my ($self, $text) = @_; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
like($self->get_title, $text, "title_like($text)"); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub is_visible_ok { |
225
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
226
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
ok($self->is_visible($locator), "is_visible($locator)"); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub attribute_like { |
232
|
|
|
|
|
|
|
my ($self, $locator, $expr) = @_; |
233
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
like($self->get_attribute($locator), $expr, "attribute_like($locator, $expr)"); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub attribute_unlike { |
239
|
|
|
|
|
|
|
my ($self, $locator, $expr) = @_; |
240
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
unlike($self->get_attribute($locator), $expr, "attribute_unlike($locator, $expr)"); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub submit_ok { |
246
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
247
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
ok($self->submit($locator), "submit_ok($locator)"); |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
sub eval_is { |
253
|
|
|
|
|
|
|
my ($self, $js, $expr) = @_; |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
is($self->eval_js($js), $expr, "eval_is($expr)"); |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub check_ok { |
259
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
260
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
ok($self->check($locator), "check_ok($locator)"); |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub uncheck_ok { |
266
|
|
|
|
|
|
|
my ($self, $locator) = @_; |
267
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
ok($self->uncheck($locator), "uncheck_ok($locator)"); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub print_requested_ok { |
273
|
|
|
|
|
|
|
my ($self) = @_; |
274
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
ok($self->print_requested, "print_requested_ok"); |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 Additions to the Selenium API |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head3 wait_for_alert_ok($text, $timeout) |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Wait for an alert with the given text to happen. |
284
|
|
|
|
|
|
|
If $text is undef, it waits for any alert. Since alerts do not get automatically cleared, this has to be done manually before causing the action that is supposed to throw a new alert: |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
$webkit->alerts([]); |
287
|
|
|
|
|
|
|
$webkit->click('...'); |
288
|
|
|
|
|
|
|
$webkit->wait_for_alert; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=cut |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
sub wait_for_alert_ok { |
293
|
|
|
|
|
|
|
my ($self, $text, $timeout) = @_; |
294
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
ok($self->wait_for_alert($text, $timeout), "wait_for_alert_ok($text)") |
297
|
|
|
|
|
|
|
or diag( |
298
|
|
|
|
|
|
|
@{ $self->alerts } |
299
|
|
|
|
|
|
|
? 'Last alert was: "' . $self->alerts->[-1] . '"' |
300
|
|
|
|
|
|
|
: 'No alert occured' |
301
|
|
|
|
|
|
|
); |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head3 native_drag_and_drop_to_position_ok($source, $target_x, $target_y, $options) |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
Drag and drop $source to position ($target_x and $target_y) |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=cut |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
sub native_drag_and_drop_to_position_ok { |
311
|
|
|
|
|
|
|
my ($self, $source, $target_x, $target_y, $options) = @_; |
312
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
$self->native_drag_and_drop_to_position($source, $target_x, $target_y, $options); |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
ok(1, "native_drag_and_drop_to_position_ok($source, $target_x, $target_y)"); |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=head3 native_drag_and_drop_to_object_ok($source, $target, $options) |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Drag and drop $source to $target. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=cut |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub native_drag_and_drop_to_object_ok { |
326
|
|
|
|
|
|
|
my ($self, $source, $target, $options) = @_; |
327
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
$self->native_drag_and_drop_to_object($source, $target, $options); |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
ok(1, "native_drag_and_drop_to_object_ok($source, $target)"); |
332
|
|
|
|
|
|
|
} |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
1; |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=head1 SEE ALSO |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
L for the base package. |
339
|
|
|
|
|
|
|
See L for API documentation. |
340
|
|
|
|
|
|
|
L for a replacement for L |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=head1 AUTHOR |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
Stefan Seifert, Enine@cpan.orgE |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
Copyright (C) 2011 by Stefan Seifert |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
351
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.12.3 or, |
352
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=cut |