File Coverage

blib/lib/Test/WWW/WebKit.pm
Criterion Covered Total %
statement 3 5 60.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 5 7 71.4


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   15843 use 5.10.0;
  1         3  
31 1     1   323 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.04';
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 is_element_present_ok {
115             my ($self, $locator) = @_;
116             local $Test::Builder::Level = $Test::Builder::Level + 1;
117              
118             my $result = $self->is_element_present($locator);
119             my $retval = ok($result, "is_element_present_ok($locator)")
120             or diag "# $@\n";
121             return $retval;
122             }
123              
124             sub type_ok {
125             my ($self, $locator, $text) = @_;
126             local $Test::Builder::Level = $Test::Builder::Level + 1;
127              
128             ok(eval { $self->type($locator, $text) }, "type_ok($locator, $text)");
129             }
130              
131             sub type_keys_ok {
132             my ($self, $locator, $text) = @_;
133             local $Test::Builder::Level = $Test::Builder::Level + 1;
134              
135             ok(eval { $self->type_keys($locator, $text) }, "type_keys_ok($locator, $text)");
136             }
137              
138             sub control_key_down_ok {
139             my ($self) = @_;
140             local $Test::Builder::Level = $Test::Builder::Level + 1;
141              
142             $self->control_key_down;
143             ok(1, "control_key_down_ok()");
144             }
145              
146             sub control_key_up_ok {
147             my ($self) = @_;
148             local $Test::Builder::Level = $Test::Builder::Level + 1;
149              
150             $self->control_key_up;
151             ok(1, "control_key_up_ok()");
152             }
153              
154             sub is_ordered_ok {
155             my ($self, $first, $second) = @_;
156             local $Test::Builder::Level = $Test::Builder::Level + 1;
157              
158             ok($self->is_ordered($first, $second), "is_ordered_ok($first, $second)");
159             }
160              
161             sub mouse_over_ok {
162             my ($self, $locator) = @_;
163             local $Test::Builder::Level = $Test::Builder::Level + 1;
164              
165             ok($self->mouse_over($locator), "mouse_over_ok($locator)");
166             }
167              
168             sub mouse_down_ok {
169             my ($self, $locator) = @_;
170             local $Test::Builder::Level = $Test::Builder::Level + 1;
171              
172             ok($self->mouse_down($locator), "mouse_down_ok($locator)");
173             }
174              
175             sub fire_event_ok {
176             my ($self, $locator, $event_type) = @_;
177             local $Test::Builder::Level = $Test::Builder::Level + 1;
178              
179             ok($self->fire_event($locator, $event_type), "fire_event_ok($locator, $event_type)");
180             }
181              
182             sub text_is {
183             my ($self, $locator, $text, $description) = @_;
184             $description //= '';
185             local $Test::Builder::Level = $Test::Builder::Level + 1;
186              
187             is($self->get_text($locator), $text, "text_is($locator, $text, $description)");
188             }
189              
190             sub text_like {
191             my ($self, $locator, $text) = @_;
192             local $Test::Builder::Level = $Test::Builder::Level + 1;
193              
194             like($self->get_text($locator), $text);
195             }
196              
197             sub body_text_like {
198             my ($self, $text) = @_;
199             local $Test::Builder::Level = $Test::Builder::Level + 1;
200              
201             like($self->get_body_text(), $text, "body_text_like($text)");
202             }
203              
204             sub value_is {
205             my ($self, $locator, $value) = @_;
206             local $Test::Builder::Level = $Test::Builder::Level + 1;
207              
208             is($self->get_value($locator), $value, "value_is($locator, $value)");
209             }
210              
211             sub title_like {
212             my ($self, $text) = @_;
213              
214             like($self->get_title, $text, "title_like($text)");
215             }
216              
217             sub is_visible_ok {
218             my ($self, $locator) = @_;
219             local $Test::Builder::Level = $Test::Builder::Level + 1;
220              
221             ok($self->is_visible($locator), "is_visible($locator)");
222             }
223              
224             sub attribute_like {
225             my ($self, $locator, $expr) = @_;
226             local $Test::Builder::Level = $Test::Builder::Level + 1;
227              
228             like($self->get_attribute($locator), $expr, "attribute_like($locator, $expr)");
229             }
230              
231             sub attribute_unlike {
232             my ($self, $locator, $expr) = @_;
233             local $Test::Builder::Level = $Test::Builder::Level + 1;
234              
235             unlike($self->get_attribute($locator), $expr, "attribute_unlike($locator, $expr)");
236             }
237              
238             sub submit_ok {
239             my ($self, $locator) = @_;
240             local $Test::Builder::Level = $Test::Builder::Level + 1;
241              
242             ok($self->submit($locator), "submit_ok($locator)");
243             }
244              
245             sub eval_is {
246             my ($self, $js, $expr) = @_;
247              
248             is($self->eval_js($js), $expr, "eval_is($expr)");
249             }
250              
251             sub check_ok {
252             my ($self, $locator) = @_;
253             local $Test::Builder::Level = $Test::Builder::Level + 1;
254              
255             ok($self->check($locator), "check_ok($locator)");
256             }
257              
258             sub uncheck_ok {
259             my ($self, $locator) = @_;
260             local $Test::Builder::Level = $Test::Builder::Level + 1;
261              
262             ok($self->uncheck($locator), "uncheck_ok($locator)");
263             }
264              
265             sub print_requested_ok {
266             my ($self) = @_;
267             local $Test::Builder::Level = $Test::Builder::Level + 1;
268              
269             ok($self->print_requested, "print_requested_ok");
270             }
271              
272             =head2 Additions to the Selenium API
273              
274             =head3 wait_for_alert_ok($text, $timeout)
275              
276             Wait for an alert with the given text to happen.
277             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:
278              
279             $webkit->alerts([]);
280             $webkit->click('...');
281             $webkit->wait_for_alert;
282              
283             =cut
284              
285             sub wait_for_alert_ok {
286             my ($self, $text, $timeout) = @_;
287             local $Test::Builder::Level = $Test::Builder::Level + 1;
288              
289             ok($self->wait_for_alert($text, $timeout), "wait_for_alert_ok($text)")
290             or diag(
291             @{ $self->alerts }
292             ? 'Last alert was: "' . $self->alerts->[-1] . '"'
293             : 'No alert occured'
294             );
295             }
296              
297             =head3 native_drag_and_drop_to_position_ok($source, $target_x, $target_y, $options)
298              
299             Drag and drop $source to position ($target_x and $target_y)
300              
301             =cut
302              
303             sub native_drag_and_drop_to_position_ok {
304             my ($self, $source, $target_x, $target_y, $options) = @_;
305             local $Test::Builder::Level = $Test::Builder::Level + 1;
306              
307             $self->native_drag_and_drop_to_position($source, $target_x, $target_y, $options);
308              
309             ok(1, "native_drag_and_drop_to_position_ok($source, $target_x, $target_y)");
310             }
311              
312             =head3 native_drag_and_drop_to_object_ok($source, $target, $options)
313              
314             Drag and drop $source to $target.
315              
316             =cut
317              
318             sub native_drag_and_drop_to_object_ok {
319             my ($self, $source, $target, $options) = @_;
320             local $Test::Builder::Level = $Test::Builder::Level + 1;
321              
322             $self->native_drag_and_drop_to_object($source, $target, $options);
323              
324             ok(1, "native_drag_and_drop_to_object_ok($source, $target)");
325             }
326              
327             1;
328              
329             =head1 SEE ALSO
330              
331             L for the base package.
332             See L for API documentation.
333             L for a replacement for L
334              
335             =head1 AUTHOR
336              
337             Stefan Seifert, Enine@cpan.orgE
338              
339             =head1 COPYRIGHT AND LICENSE
340              
341             Copyright (C) 2011 by Stefan Seifert
342              
343             This library is free software; you can redistribute it and/or modify
344             it under the same terms as Perl itself, either Perl version 5.12.3 or,
345             at your option, any later version of Perl 5 you may have available.
346              
347             =cut