lib/Selenium/Client.pm

filter: Statementstmt 27.2% 73 / 268 Branchbran 0.0% 0 / 130 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 51.2% 21 / 41 Podpod 100% 2 / 2 totaltotal 17.8% 96 / 539 CC 104 SCAR 58.6
CC
104
Cov
16%
_request
1122.0
new
420.0
DESTROY
156.0
CRAP 349.6
↑ Summary lib/Selenium/Specification.pm »
1 package Selenium::Client;
2 2 $Selenium::Client::VERSION = '2.01';
3 # ABSTRACT: Module for communicating with WC3 standard selenium servers
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use v5.28.0; # Before 5.006, v5.10.0 would not be understood.
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use feature qw/signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use JSON::MaybeXS();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use HTTP::Tiny();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Carp qw{confess cluck};
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use File::Path qw{make_path};
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use File::HomeDir();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use File::Slurper();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use File::Spec();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Sub::Install();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use Net::EmptyPort();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use Capture::Tiny qw{capture_merged};
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Unicode::Normalize qw{NFC};
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 ▶use Selenium::Specification;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28  
29 0 ▶sub new ( $class, %options ) {
Subroutine new: not called CC=20 SCAR=60.4
Pod documented
30 0 ▶ $options{version} //= 'stable';
Condition0%0/2
$options{"version"} //= "stable"
l!l
00
MC/DC0%0/1
$options{"version"} //= "stable"
$options{"version"}
Truth table0%0/2
A
A= $options{"version"}
Aresult
11
00
31 0 ▶ $options{port} //= 4444;
Condition0%0/2
$options{"port"} //= 4444
l!l
00
MC/DC0%0/1
$options{"port"} //= 4444
$options{"port"}
Truth table0%0/2
A
A= $options{"port"}
Aresult
11
00
32  
33 #XXX geckodriver doesn't bind to localhost lol
34 0 ▶ $options{host} //= '127.0.0.1';
Condition0%0/2
$options{"host"} //= "127.0.0.1"
l!l
00
MC/DC0%0/1
$options{"host"} //= "127.0.0.1"
$options{"host"}
Truth table0%0/2
A
A= $options{"host"}
Aresult
11
00
35 0 ▶ $options{host} = '127.0.0.1' if $options{host} eq 'localhost';
Branch: 1 branch
BranchTrueFalseTotal
if $options{"host"} eq "localhost" 0 0 0
36  
37 0 ▶ $options{nofetch} //= 1;
Condition0%0/2
$options{"nofetch"} //= 1
l!l
00
MC/DC0%0/1
$options{"nofetch"} //= 1
$options{"nofetch"}
Truth table0%0/2
A
A= $options{"nofetch"}
Aresult
11
00
38 0 ▶ $options{scheme} //= 'http';
Condition0%0/2
$options{"scheme"} //= "http"
l!l
00
MC/DC0%0/1
$options{"scheme"} //= "http"
$options{"scheme"}
Truth table0%0/2
A
A= $options{"scheme"}
Aresult
11
00
39 0 ▶ $options{prefix} //= '';
Condition0%0/2
$options{"prefix"} //= ""
l!l
00
MC/DC0%0/1
$options{"prefix"} //= ""
$options{"prefix"}
Truth table0%0/2
A
A= $options{"prefix"}
Aresult
11
00
40 0 ▶ $options{ua} //= HTTP::Tiny->new();
Condition0%0/3
$options{"ua"} //= "HTTP::Tiny"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"ua"} //= "HTTP::Tiny"->new
$options{"ua"} "HTTP::Tiny"->new
Truth table0%0/3
A //= B
A= $options{"ua"}B= "HTTP::Tiny"->new
ABresult
1X1
011
000
41 0 ▶ $options{client_dir} //= File::HomeDir::my_home() . "/.selenium";
Condition0%0/2
$options{"client_dir"} //= File::HomeDir::my_home() . '/.selenium'
l!l
00
MC/DC0%0/1
$options{"client_dir"} //= File::HomeDir::my_home() . '/.selenium'
$options{"client_dir"}
Truth table0%0/2
A
A= $options{"client_dir"}
Aresult
11
00
42 0 ▶ $options{driver} //= "SeleniumHQ::Jar";
Condition0%0/2
$options{"driver"} //= "SeleniumHQ::Jar"
l!l
00
MC/DC0%0/1
$options{"driver"} //= "SeleniumHQ::Jar"
$options{"driver"}
Truth table0%0/2
A
A= $options{"driver"}
Aresult
11
00
43 0 ▶ $options{post_callbacks} //= [];
Condition0%0/2
$options{"post_callbacks"} //= []
l!l
00
MC/DC0%0/1
$options{"post_callbacks"} //= []
$options{"post_callbacks"}
Truth table0%0/2
A
A= $options{"post_callbacks"}
Aresult
11
00
44 0 ▶ $options{auto_close} //= 1;
Condition0%0/2
$options{"auto_close"} //= 1
l!l
00
MC/DC0%0/1
$options{"auto_close"} //= 1
$options{"auto_close"}
Truth table0%0/2
A
A= $options{"auto_close"}
Aresult
11
00
45 0 ▶ $options{browser} //= '';
Condition0%0/2
$options{"browser"} //= ""
l!l
00
MC/DC0%0/1
$options{"browser"} //= ""
$options{"browser"}
Truth table0%0/2
A
A= $options{"browser"}
Aresult
11
00
46 0 ▶ $options{headless} //= 1;
Condition0%0/2
$options{"headless"} //= 1
l!l
00
MC/DC0%0/1
$options{"headless"} //= 1
$options{"headless"}
Truth table0%0/2
A
A= $options{"headless"}
Aresult
11
00
47 0 ▶ $options{normalize} //= 1;
Condition0%0/2
$options{"normalize"} //= 1
l!l
00
MC/DC0%0/1
$options{"normalize"} //= 1
$options{"normalize"}
Truth table0%0/2
A
A= $options{"normalize"}
Aresult
11
00
48 0 ▶ $options{fatal} //= 1;
Condition0%0/2
$options{"fatal"} //= 1
l!l
00
MC/DC0%0/1
$options{"fatal"} //= 1
$options{"fatal"}
Truth table0%0/2
A
A= $options{"fatal"}
Aresult
11
00
49  
50 # Use the hardcoded JSON version of the stable spec in Selenium::Specification's DATA section.
51 0 ▶ $options{hardcode} //= 1;
Condition0%0/2
$options{"hardcode"} //= 1
l!l
00
MC/DC0%0/1
$options{"hardcode"} //= 1
$options{"hardcode"}
Truth table0%0/2
A
A= $options{"hardcode"}
Aresult
11
00
52 0 ▶ $options{capabilities} //= {};
Condition0%0/2
$options{"capabilities"} //= {}
l!l
00
MC/DC0%0/1
$options{"capabilities"} //= {}
$options{"capabilities"}
Truth table0%0/2
A
A= $options{"capabilities"}
Aresult
11
00
53  
54 #create client_dir and log-dir
55 0 my $dir = File::Spec->catdir( $options{client_dir}, "perl-client" );
56 0 make_path($dir);
57  
58 #Grab the spec
59 0 $options{spec} = Selenium::Specification::read( $options{client_dir}, $options{version}, $options{nofetch}, $options{hardcode} );
60  
61 0 my $self = bless( \%options, $class );
62 0 $self->{sessions} = [];
63  
64 0 $self->_build_subs();
65 0 ▶ $self->_spawn() if $options{host} eq '127.0.0.1';
Branch: 1 branch
BranchTrueFalseTotal
if $options{"host"} eq "127.0.0.1" 0 0 0
66 0 return $self;
67 }
68  
69  
70 0 ▶sub catalog ( $self, $printed = 0 ) {
Subroutine catalog: not called CC=4 SCAR=30.0
Pod documented
71 0 ▶ return $self->{spec} unless $printed;
Branch: 1 branch
BranchTrueFalseTotal
unless $printed 0 0 0
72 0 foreach my $method ( keys( %{ $self->{spec} } ) ) {
73 0 print "$method: $self->{spec}{$method}{href}\n";
74 }
75 0 return $self->{spec};
76 }
77  
78 my %browser_opts = (
79 firefox => {
80 name => 'moz:firefoxOptions',
81 0 ▶ headless => sub ($c) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
82 0 ▶ $c->{args} //= [];
Condition0%0/2
$c->{"args"} //= []
l!l
00
MC/DC0%0/1
$c->{"args"} //= []
$c->{"args"}
Truth table0%0/2
A
A= $c->{"args"}
Aresult
11
00
83 0 push( @{ $c->{args} }, '-headless' );
84 },
85 },
86 chrome => {
87 name => 'goog:chromeOptions',
88 0 ▶ headless => sub ($c) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
89 0 ▶ $c->{args} //= [];
Condition0%0/2
$c->{"args"} //= []
l!l
00
MC/DC0%0/1
$c->{"args"} //= []
$c->{"args"}
Truth table0%0/2
A
A= $c->{"args"}
Aresult
11
00
90 0 push( @{ $c->{args} }, 'headless' );
91 },
92 },
93 MicrosoftEdge => {
94 name => 'ms:EdgeOptions',
95 0 ▶ headless => sub ($c) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
96 0 ▶ $c->{args} //= [];
Condition0%0/2
$c->{"args"} //= []
l!l
00
MC/DC0%0/1
$c->{"args"} //= []
$c->{"args"}
Truth table0%0/2
A
A= $c->{"args"}
Aresult
11
00
97 0 push( @{ $c->{args} }, 'headless' );
98 },
99 },
100 2 );
101  
102 0 ▶sub _build_caps ( $self, %options ) {
Subroutine _build_caps: not called CC=7 SCAR=40.3
103 0 ▶ $options{browser} = $self->{browser} if $self->{browser};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"browser"} 0 0 0
104 0 ▶ $options{headless} = $self->{headless} if $self->{headless};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"headless"} 0 0 0
105  
106 my $c = {
107 browserName => $options{browser},
108 0 %{ $self->{capabilities} },
109 };
110 0 my $browser = $browser_opts{ $options{browser} };
111  
112 0 ▶ if ($browser) {
Branch: 1 branch
BranchTrueFalseTotal
if ($browser) 0 0 0
113 0 my $browseropts = {};
114 0 foreach my $k ( keys %$browser ) {
115 0 ▶ next if $k eq 'name';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "name" 0 0 0
116 0 ▶ $browser->{$k}->($browseropts) if $options{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $options{$k} 0 0 0
117 }
118 0 $c->{ $browser->{name} } = $browseropts;
119 }
120  
121 return (
122 0 capabilities => {
123 alwaysMatch => $c,
124 },
125 );
126 }
127  
128 0 ▶sub _build_subs ($self) {
Subroutine _build_subs: not called CC=4 SCAR=30.0
129 0 foreach my $sub ( keys( %{ $self->{spec} } ) ) {
130 0 ▶ print "Installing $self->{spec}{$sub}{uri} as $self->{spec}{$sub}{name}\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
131 Sub::Install::install_sub(
132 {
133 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
134 0 my $self = shift;
135 0 return $self->_request( $sub, @_ );
136 },
137 0 ▶ as => $sub,
Branch: 1 branch
BranchTrueFalseTotal
unless "Selenium::Client"->can($sub) 0 0 0
138 into => "Selenium::Client",
139 }
140 ) unless "Selenium::Client"->can($sub);
141 }
142 }
143  
144 #Check if server already up and spawn if no
145 0 ▶sub _spawn ($self) {
Subroutine _spawn: not called CC=3 SCAR=24.8
146 0 ▶ return $self->Status() if Net::EmptyPort::wait_port( $self->{port}, 1 );
Branch: 1 branch
BranchTrueFalseTotal
if Net::EmptyPort::wait_port($self->{"port"}, 1) 0 0 0
147  
148 # Pick a random port for the new server
149 0 $self->{port} = Net::EmptyPort::empty_port();
150  
151 0 my $driver_file = "Selenium/Driver/$self->{driver}.pm";
152 0 $driver_file =~ s/::/\//g;
153 0 ▶ eval { require $driver_file } or confess "Could not load $driver_file, check your PERL5LIB: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $driver_file } } or confess("Could not load $driver_file, check your PERL5LIB: $@") 0 0 0
154 0 my $driver = "Selenium::Driver::$self->{driver}";
155  
156 0 $driver->build_spawn_opts($self);
157 0 return $self->_do_spawn();
158 }
159  
160 0 ▶sub _do_spawn ($self) {
Subroutine _do_spawn: not called CC=7 SCAR=40.3
161  
162 #XXX on windows we will *never* terminate if we are listening for *anything*
163 #XXX so we have to just bg & ignore, unfortunately (also have to system())
164 0 ▶ if ( _is_windows() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_windows()) 0 0 0
165 0 $self->{pid} = qq/$self->{driver}:$self->{port}/;
166 0 my @cmdprefix = ( "start /MIN", qq{"$self->{pid}"} );
167  
168 # Selenium JAR controls it's own logging because Java
169 0 my @cmdsuffix;
170 0 ▶ @cmdsuffix = ( '>', $self->{log_file}, '2>&1' ) unless $self->{driver_class} eq 'Selenium::Driver::SeleniumHQ::Jar';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"driver_class"} eq "Selenium::Driver::SeleniumHQ::Jar" 0 0 0
171  
172 0 my $cmdstring = join( ' ', @cmdprefix, @{ $self->{command} }, @cmdsuffix );
173 0 ▶ print "$cmdstring\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
174 0 system($cmdstring);
175 0 return $self->_wait();
176 }
177  
178 0 ▶ print "@{$self->{command}}\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
179 0 ▶ my $pid = fork // confess("Could not fork");
Condition0%0/2
fork // confess("Could not fork")
l!l
00
MC/DC0%0/1
fork // confess("Could not fork")
fork
Truth table0%0/2
A
A= fork
Aresult
11
00
180 0 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) 0 0 0
181 0 $self->{pid} = $pid;
182 0 return $self->_wait();
183 }
184 0 open( my $fh, '>>', $self->{log_file} );
185 0 ▶ capture_merged { exec( @{ $self->{command} } ) } stdout => $fh;
Subroutine __ANON__: not called CC=1 SCAR=6.9
186 }
187  
188 0 ▶sub _wait ($self) {
Subroutine _wait: not called CC=4 SCAR=30.0
189 0 ▶ print "Waiting for port to come up..." if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
190 0 ▶ Net::EmptyPort::wait_port( $self->{port}, 30 )
Branch: 1 branch
BranchTrueFalseTotal
Net::EmptyPort::wait_port($self->{"port"}, 30) or confess(qq[Server never came up on port $self->{"port"} after 30s!]) 0 0 0
191 or confess("Server never came up on port $self->{port} after 30s!");
192 0 ▶ print "done\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
193 0 return $self->Status();
194 }
195  
196 0 ▶sub DESTROY ($self) {
Subroutine DESTROY: not called CC=12 SCAR=50.5
197 0 ▶ return unless $self->{auto_close};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"auto_close"} 0 0 0
198  
199 0 local $?; # Avoid affecting the exit status
200  
201 #Kill the server if we spawned one
202 0 ▶ return unless $self->{pid};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"pid"} 0 0 0
203 0 ▶ print "Attempting to kill server process...\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
204  
205 0 ▶ if ( _is_windows() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_windows()) 0 0 0
206 0 my $killer = qq[taskkill /FI "WINDOWTITLE eq $self->{pid}"];
207 0 ▶ print "$killer\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
208  
209 #$killer .= ' > nul 2&>1' unless $self->{debug};
210 0 system($killer);
211 0 return 1;
212 }
213  
214 0 my $sig = 'TERM';
215 0 kill $sig, $self->{pid};
216  
217 0 ▶ print "Issued SIG$sig to $self->{pid}, waiting...\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
218  
219 # 0 is always WCONTINUED, 1 is always WNOHANG, and POSIX is an expensive import
220 # When 0 is returned, the process is still active, so it needs more persuasion
221 0 foreach ( 0 .. 3 ) {
222 0 ▶ return unless waitpid( $self->{pid}, 1 ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless waitpid($self->{"pid"}, 1) == 0 0 0 0
223 0 sleep 1;
224 }
225  
226 # Advanced persuasion
227 0 ▶ print "Forcibly terminating selenium server process...\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
228 0 kill( 'TERM', $self->{pid} );
229  
230 #XXX unfortunately I can't just do a SIGALRM, because blocking system calls can't be intercepted on win32
231 0 foreach ( 0 .. $self->{timeout} ) {
232 0 ▶ return unless waitpid( $self->{pid}, 1 ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless waitpid($self->{"pid"}, 1) == 0 0 0 0
233 0 sleep 1;
234 }
235 0 warn "Could not shut down selenium server!";
236 0 return;
237 }
238  
239 0 ▶sub _is_windows {
Subroutine _is_windows: not called CC=1 SCAR=6.9
240 0 return grep { $^O eq $_ } qw{msys MSWin32};
241 }
242  
243 #XXX some of the methods require content being null, some require it to be an obj with no params LOL
244 2 our @bad_methods = qw{AcceptAlert DismissAlert Back Forward Refresh ElementClick MaximizeWindow MinimizeWindow FullscreenWindow SwitchToParentFrame ElementClear};
245  
246 #Exempt some calls from return processing
247 2 our @no_process = qw{Status GetAlertText GetTimeouts GetWindowRect GetElementRect GetAllCookies};
248  
249 0 ▶sub _request ( $self, $method, %params ) {
Subroutine _request: not called CC=33 SCAR=70.2
250 0 my $subject = $self->{spec}->{$method};
251  
252 #TODO handle compressed output from server
253 0 my %options = (
254 headers => {
255 'Content-Type' => 'application/json; charset=utf-8',
256 'Accept' => 'application/json; charset=utf-8',
257 'Accept-Encoding' => 'identity',
258 },
259 );
260 0 ▶ $options{content} = '{}' if grep { $_ eq $method } @bad_methods;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $method;} @Selenium::Client::bad_methods 0 0 0
261  
262 0 my $url = "$self->{scheme}://$self->{host}:$self->{port}$subject->{uri}";
263  
264 # Remove parameters to inject into child objects
265 0 ▶ my $inject_key = exists $params{inject} ? delete $params{inject} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $params{'inject'} ? : 0 0 0
266 0 ▶ my $inject_value = $inject_key ? $params{$inject_key} : '';
Branch: 1 branch
BranchTrueFalseTotal
$inject_key ? : 0 0 0
267 0 my $inject;
268 0 ▶ $inject = { to_inject => { $inject_key => $inject_value } } if $inject_key && $inject_value;
Branch: 1 branch
BranchTrueFalseTotal
if $inject_key and $inject_value 0 0 0
Condition0%0/3
$inject_key and $inject_value
!ll&&!rl&&r
000
MC/DC0%0/2
$inject_key and $inject_value
$inject_key $inject_value
Truth table0%0/3
A and B
A= $inject_keyB= $inject_value
ABresult
0X0
100
111
269  
270 # Keep sessions for passing to grandchildren
271 0 ▶ $inject->{to_inject}{sessionid} = $params{sessionid} if exists $params{sessionid};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"sessionid"} 0 0 0
272  
273 #If we have no extra params, and this is getSession, simplify
274 0 ▶ %params = $self->_build_caps() if $method eq 'NewSession' && !%params;
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "NewSession" and not %params 0 0 0
Condition0%0/3
$method eq "NewSession" and not %params
!ll&&!rl&&r
000
MC/DC0%0/2
$method eq "NewSession" and not %params
$method eq "NewSession" not %params
Truth table0%0/3
A and not(B)
A= $method eq "NewSession"B= not %params
ABresult
0X0
100
111
275  
276 0 my @needed_params = $subject->{uri} =~ m/\{(\w+)\}/g;
277 0 foreach my $param (@needed_params) {
278 0 ▶ confess "$param is required for $method" unless exists $params{$param};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{$param} 0 0 0
279 0 ▶ delete $params{$param} if $url =~ s/{\Q$param\E}/$params{$param}/g;
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ s/{\Q$param\E}/$params{$param}/gu 0 0 0
280 }
281  
282 0 ▶ if (%params) {
Branch: 1 branch
BranchTrueFalseTotal
if (%params) 0 0 0
283 0 $options{content} = JSON::MaybeXS::encode_json( \%params );
284 0 $options{headers}{'Content-Length'} = length( $options{content} );
285 }
286  
287 0 ▶ print "$subject->{method} $url\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
288 0 ▶ print "Body: $options{content}\n" if $self->{debug} && exists $options{content};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} and exists $options{"content"} 0 0 0
Condition0%0/3
$self->{"debug"} and exists $options{"content"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"debug"} and exists $options{"content"}
$self->{"debug"} exists $options{"content"}
Truth table0%0/3
A and B
A= $self->{"debug"}B= exists $options{"content"}
ABresult
0X0
100
111
289  
290 0 my $res = $self->{ua}->request( $subject->{method}, $url, \%options );
291  
292 0 my @cbret;
293 0 foreach my $cb ( @{ $self->{post_callbacks} } ) {
294 0 ▶ if ( $cb && ref $cb eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb and ref $cb eq "CODE") 0 0 0
Condition0%0/3
$cb and ref $cb eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$cb and ref $cb eq "CODE"
$cb ref $cb eq "CODE"
Truth table0%0/3
A and B
A= $cbB= ref $cb eq "CODE"
ABresult
0X0
100
111
295 0 @options{qw{url method}} = ( $url, $subject->{method} );
296 0 ▶ $options{content} = \%params if %params;
Branch: 1 branch
BranchTrueFalseTotal
if %params 0 0 0
297 0 my $ret = $cb->( $self, $res, \%options );
298 0 ▶ push( @cbret, $ret ) if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
299 }
300 0 ▶ return $cbret[0] if @cbret == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @cbret == 1 0 0 0
301 0 ▶ return @cbret if @cbret;
Branch: 1 branch
BranchTrueFalseTotal
if @cbret 0 0 0
302 }
303  
304 0 ▶ print "$res->{status} : $res->{content}\n" if $self->{debug} && ref $res eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} and ref $res eq "HASH" 0 0 0
Condition0%0/3
$self->{"debug"} and ref $res eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"debug"} and ref $res eq "HASH"
$self->{"debug"} ref $res eq "HASH"
Truth table0%0/3
A and B
A= $self->{"debug"}B= ref $res eq "HASH"
ABresult
0X0
100
111
305  
306 # all the selenium servers are UTF-8
307 0 my $normal = $res->{content};
308 0 ▶ $normal = NFC($normal) if $self->{normalize};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"normalize"} 0 0 0
309 0 my $decoded_content = eval { JSON::MaybeXS->new()->utf8()->decode($normal) };
310  
311 0 ▶ if ( $self->{fatal} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'fatal'}) { } 0 0 0
312 0 ▶ confess "$res->{reason} :\n Consult $subject->{href}\nRaw Error:\n$res->{content}\n" unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
313 }
314 else {
315 0 ▶ cluck "$res->{reason} :\n Consult $subject->{href}\nRaw Error:\n$res->{content}\n" unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
316 }
317  
318 #XXX should be caught below by objectify
319 0 ▶ if ( grep { $method eq $_ } @no_process ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$method eq $_;} @Selenium::Client::no_process) 0 0 0
320 0 ▶ if ( ref $decoded_content->{value} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $decoded_content->{"value"} eq "ARRAY") 0 0 0
321 0 ▶ return wantarray ? @{ $decoded_content->{value} } : $decoded_content->{value};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
322 }
323 0 return $decoded_content->{value};
324 }
325  
326 #XXX sigh
327 0 ▶ if ( $decoded_content->{sessionId} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decoded_content->{"sessionId"}) 0 0 0
328 0 $decoded_content->{value} = [ { capabilities => $decoded_content->{value} }, { sessionId => $decoded_content->{sessionId} } ];
329 }
330  
331 0 return $self->_objectify( $decoded_content, $inject );
332 }
333  
334 our %classes = (
335 capabilities => { class => 'Selenium::Capabilities' },
336 sessionId => {
337 class => 'Selenium::Session',
338 0 ▶ destroy_callback => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
339 0 my $self = shift;
340 0 ▶ $self->DeleteSession( sessionid => $self->{sessionid} ) unless $self->{deleted};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"deleted"} 0 0 0
341 },
342 0 ▶ callback => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
343 0 my ( $self, $call ) = @_;
344 0 ▶ $self->{deleted} = 1 if $call eq 'DeleteSession';
Branch: 1 branch
BranchTrueFalseTotal
if $call eq "DeleteSession" 0 0 0
345 },
346 },
347  
348 # Whoever thought this parameter name was a good idea...
349 2 'element-6066-11e4-a52e-4f735466cecf' => {
350 class => 'Selenium::Element',
351 },
352 );
353  
354 0 ▶sub _objectify ( $self, $result, $inject ) {
Subroutine _objectify: not called CC=12 SCAR=50.5
355 0 my $subject = $result->{value};
356 0 ▶ return $subject unless grep { ref $subject eq $_ } qw{ARRAY HASH};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {ref $subject eq $_;} "ARRAY", "HASH" 0 0 0
357 0 ▶ $subject = [$subject] unless ref $subject eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $subject eq "ARRAY" 0 0 0
358  
359 0 my @objs;
360 0 foreach my $to_objectify (@$subject) {
361  
362 # If we have just data return it
363 0 ▶ return wantarray ? @$subject : $subject if ref $to_objectify ne 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
if ref $to_objectify ne "HASH" 0 0 0
wantarray ? : 0 0 0
364  
365 0 my @objects = keys(%$to_objectify);
366 0 foreach my $object (@objects) {
367  
368 0 my $has_class = exists $classes{$object};
369  
370 0 ▶ my $base_object = $inject // {};
Condition0%0/2
$inject // {}
l!l
00
MC/DC0%0/1
$inject // {}
$inject
Truth table0%0/2
A
A= $inject
Aresult
11
00
371 0 $base_object->{ lc($object) } = $to_objectify->{$object};
372 0 $base_object->{sortField} = lc($object);
373  
374 my $to_push =
375 $has_class
376 0 ▶ ? $classes{$object}{class}->new( $self, $base_object )
Branch: 1 branch
BranchTrueFalseTotal
$has_class ? : 0 0 0
377 : $to_objectify;
378 0 $to_push->{sortField} = lc($object);
379  
380 # Save sessions for destructor
381 0 ▶ push( @{ $self->{sessions} }, $to_push->session_id ) if ref $to_push eq 'Selenium::Session';
Branch: 1 branch
BranchTrueFalseTotal
if ref $to_push eq "Selenium::Session" 0 0 0
382 0 push( @objs, $to_push );
383 }
384 }
385 0 @objs = sort { $a->{sortField} cmp $b->{sortField} } @objs;
386 0 ▶ return $objs[0] if @objs == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @objs == 1 0 0 0
387 0 ▶ return wantarray ? @objs : \@objs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
388 }
389  
390 2 1;
391  
392  
393 package Selenium::Capabilities;
394 2 $Selenium::Capabilities::VERSION = '2.01';
395 2 ▶use parent qw{Selenium::Subclass};
Subroutine BEGIN: called CC=1 SCAR=0.0
396 2 1;
397  
398 package Selenium::Session;
399 2 $Selenium::Session::VERSION = '2.01';
400 0 ▶sub session_id {
Subroutine session_id: not called CC=2 SCAR=17.9
401 0 my $self = shift;
402 0 ▶ return $self->{sessionId} // $self->{sessionid};
Condition0%0/3
$self->{"sessionId"} // $self->{"sessionid"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sessionId"} // $self->{"sessionid"}
$self->{"sessionId"} $self->{"sessionid"}
Truth table0%0/3
A // B
A= $self->{"sessionId"}B= $self->{"sessionid"}
ABresult
1X1
011
000
403 }
404  
405 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
406 0 my $self = shift;
407 0 ▶ return if $self->{deleted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"deleted"} 0 0 0
408 0 $self->DeleteSession( sessionid => $self->session_id );
409 }
410  
411 2 ▶use parent qw{Selenium::Subclass};
Subroutine BEGIN: called CC=1 SCAR=0.0
412 2 1;
413  
414 package Selenium::Element;
415 2 $Selenium::Element::VERSION = '2.01';
416 2 ▶use parent qw{Selenium::Subclass};
Subroutine BEGIN: called CC=1 SCAR=0.0
417 2 1;
418  
419 __END__
↑ Summary lib/Selenium/Specification.pm »