File Coverage

blib/lib/WebDriver/Tiny/Elements.pm
Criterion Covered Total %
statement 94 103 91.2
branch 1 6 16.6
condition n/a
subroutine 26 27 96.3
pod 21 22 95.4
total 142 158 89.8


line stmt bran cond sub pod time code
1             package WebDriver::Tiny::Elements 0.104;
2              
3 41     41   1394 use 5.020;
  41         178  
4 41     41   255 use feature qw/postderef signatures/;
  41         99  
  41         4442  
5 41     41   267 use warnings;
  41         82  
  41         1486  
6 41     41   735 no warnings 'experimental';
  41         126  
  41         51559  
7              
8             # Manip
9 2     2 1 19 sub append { bless [ shift->@*, map @$_[ 1.. $#$_ ], @_ ] }
10 1     1 1 101 sub first { bless [ $_[0]->@[ 0, 1 ] ] }
11 1     1 1 7 sub last { bless [ $_[0]->@[ 0, -1 ] ] }
12 1     1 1 3 sub size { $#{ $_[0] } }
  1         8  
13 6     6 1 23 sub slice { my ( $drv, @ids ) = shift->@*; bless [ $drv, @ids[@_] ] }
  6         38  
14 3     3 1 11 sub split { my ( $drv, @ids ) = $_[0]->@*; map { bless [ $drv, $_ ] } @ids }
  3         9  
  10         34  
15              
16 1     1 1 3 sub uniq($self) {
  1         2  
  1         2  
17 1         4 my ( $drv, @ids ) = @$self;
18              
19 1         2 bless [ $drv, keys %{ { map { $_ => undef } @ids } } ];
  1         2  
  11         52  
20             }
21              
22 1     1 1 96 sub attr($self, $value) { $self->_req( GET => "/attribute/$value" ) }
  1         2  
  1         4  
  1         1  
  1         8  
23 1     1 1 92 sub css($self, $value) { $self->_req( GET => "/css/$value" ) }
  1         3  
  1         2  
  1         2  
  1         8  
24 1     1 0 97 sub prop($self, $value) { $self->_req( GET => "/property/$value" ) }
  1         3  
  1         3  
  1         3  
  1         8  
25              
26 1     1 1 709 sub clear($self) { $self->_req( POST => '/clear' ); $self }
  1         3  
  1         2  
  1         6  
  1         7  
27 1     1 1 535 sub click($self) { $self->_req( POST => '/click' ); $self }
  1         4  
  1         2  
  1         5  
  1         5  
28 1     1 1 547 sub tap($self) { $self->_req( POST => '/tap' ); $self }
  1         3  
  1         2  
  1         5  
  1         4  
29              
30 1     1 1 145 sub enabled($self) { $self->_req( GET => '/enabled' ) }
  1         3  
  1         2  
  1         5  
31 1     1 1 90 sub rect($self) { $self->_req( GET => '/rect' ) }
  1         3  
  1         3  
  1         3  
32 1     1 1 87 sub selected($self) { $self->_req( GET => '/selected' ) }
  1         3  
  1         2  
  1         5  
33 1     1 1 88 sub tag($self) { $self->_req( GET => '/name' ) }
  1         3  
  1         2  
  1         4  
34 1     1 1 90 sub visible($self) { $self->_req( GET => '/displayed' ) }
  1         4  
  1         1  
  1         5  
35              
36 1     1 1 975 sub html { $_[0][0]->js( 'return arguments[0].outerHTML', $_[0] ) }
37              
38             *find = \&WebDriver::Tiny::find;
39              
40 1     1 1 958 sub screenshot($self, $file = undef) {
  1         2  
  1         3  
  1         2  
41 1         6 require MIME::Base64;
42              
43 1         3 my $data = MIME::Base64::decode_base64(
44             $self->_req( GET => '/screenshot' )
45             );
46              
47 1 50       6 if ( defined $file ) {
48 0 0       0 open my $fh, '>', $file or die $!;
49 0         0 print $fh $data;
50 0 0       0 close $fh or die $!;
51              
52 0         0 return $self;
53             }
54              
55 1         3 $data;
56             }
57              
58 1     1 1 87 sub send_keys($self, $keys) {
  1         3  
  1         2  
  1         2  
59 1         8 $self->_req( POST => '/value', { text => "$keys" } );
60 1         4 $self;
61             }
62              
63 0     0 1 0 sub text($self) {
  0         0  
  0         0  
64 0         0 my ( $drv, @ids ) = @$self;
65              
66 0         0 join ' ', map $drv->_req( GET => "/element/$_/text" ), @ids;
67             }
68              
69             # Call driver's ->_req, prepend "/element/:id" to the path first.
70 13     13   165 sub _req { $_[0][0]->_req( $_[1], "/element/$_[0][1]$_[2]", $_[3] ) }
71              
72             1;