lib/Selenium/Driver/SeleniumHQ/Jar.pm

filter: Statementstmt 37.6% 38 / 101 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 75.0% 12 / 16 Podpod 66.6% 2 / 3 totaltotal 29.5% 52 / 176 CC 26 SCAR 42.1
CC
26
Cov
26%
find_and_fetch_old_releases
132.0
build_spawn_opts
110.0
find_and_fetch
30.0
CRAP 67.1
« lib/Selenium/Specification.pm ↑ Summary lib/Selenium/Client/Driver.pm »
1 package Selenium::Driver::SeleniumHQ::Jar;
2 1 $Selenium::Driver::SeleniumHQ::Jar::VERSION = '2.01';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use feature qw/signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Carp qw{confess};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename qw{basename};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Path qw{make_path};
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Spec();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use XML::LibXML();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use HTTP::Tiny();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Github::ReleaseFetcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #ABSTRACT: Download the latest version of seleniumHQ's selenium.jar, and tell Selenium::Client how to spawn it
20  
21  
22 1 our $index = 'http://selenium-release.storage.googleapis.com';
23  
24 0 ▶sub build_spawn_opts ( $class, $object ) {
Subroutine build_spawn_opts: not called CC=10 SCAR=47.0
Pod documented
25 0 $object->{driver_class} = $class;
26 0 ▶ $object->{driver_interpreter} //= 'java';
Condition0%0/2
$object->{"driver_interpreter"} //= "java"
l!l
00
MC/DC0%0/1
$object->{"driver_interpreter"} //= "java"
$object->{"driver_interpreter"}
Truth table0%0/2
A
A= $object->{"driver_interpreter"}
Aresult
11
00
27 0 ▶ $object->{driver_version} //= '';
Condition0%0/2
$object->{"driver_version"} //= ""
l!l
00
MC/DC0%0/1
$object->{"driver_version"} //= ""
$object->{"driver_version"}
Truth table0%0/2
A
A= $object->{"driver_version"}
Aresult
11
00
28 0 ▶ $object->{log_file} //= File::Spec->catfile( $object->{client_dir}, "perl-client", "selenium-$object->{port}.log" );
Condition0%0/3
$object->{"log_file"} //= "File::Spec"->catfile($object->{"client_dir"}, "perl-client", qq[selenium-$object->{"port"}.log])
l!l&&r!l&&!r
000
MC/DC0%0/2
$object->{"log_file"} //= "File::Spec"->catfile($object->{"client_dir"}, "perl-client", qq[selenium-$object->{"port"}.log])
$object->{"log_file"} "File::Spec"->catfile($object->{"client_dir"}, "perl-client", qq[selenium-$object->{"port"}.log])
Truth table0%0/3
A //= B
A= $object->{"log_file"}B= "File::Spec"->catfile($object->{"client_dir"}, "perl-client", qq[selenium-$object->{"port"}.log])
ABresult
1X1
011
000
29  
30 # Default to new selenium versions, but allow fetching old stuff
31 0 $object->{driver_major_version} = 4;
32 0 ▶ ( $object->{driver_major_version} ) = $object->{driver_version} =~ m/-(\d+)\.\d+\.\d.*\.jar$/ if $object->{driver_version};
Branch: 1 branch
BranchTrueFalseTotal
if $object->{"driver_version"} 0 0 0
33  
34 0 ▶ die "Could not determine driver major version!" unless $object->{driver_major_version};
Branch: 1 branch
BranchTrueFalseTotal
unless $object->{"driver_major_version"} 0 0 0
35  
36 0 ▶ if ( $object->{driver_major_version} < 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->{'driver_major_version'} < 4) { } 0 0 0
37 0 ( $object->{driver_file}, $object->{driver_major_version} ) = find_and_fetch_old_releases( File::Spec->catdir( $object->{client_dir}, "jars" ), $object->{driver_version}, $object->{ua} );
38 }
39 else {
40 0 ( $object->{driver_file}, $object->{driver_major_version} ) = find_and_fetch( File::Spec->catdir( $object->{client_dir}, "jars" ), $object->{driver_version}, $object->{ua} );
41 }
42 0 ▶ $object->{driver_config} //= _build_config($object);
Condition0%0/3
$object->{"driver_config"} //= _build_config($object)
l!l&&r!l&&!r
000
MC/DC0%0/2
$object->{"driver_config"} //= _build_config($object)
$object->{"driver_config"} _build_config($object)
Truth table0%0/3
A //= B
A= $object->{"driver_config"}B= _build_config($object)
ABresult
1X1
011
000
43  
44 #XXX port in config is currently IGNORED
45 0 my @java_opts;
46 0 my @config = ( (qw{standalone --config}), $object->{driver_config}, '--port', $object->{port} );
47  
48 # Handle older seleniums that are WC3 compliant
49 0 ▶ if ( $object->{driver_major_version} < 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->{"driver_major_version"} < 4) 0 0 0
50 0 $object->{prefix} = '/wd/hub';
51 0 @java_opts = qw{-Dwebedriver.gecko.driver=geckodriver -Dwebdriver.chrome.driver=chromedriver};
52 0 @config = ();
53 }
54  
55 # Build command string
56 # XXX relies on gecko/chromedriver in $PATH
57 $object->{command} //= [
58 $object->{driver_interpreter},
59 @java_opts,
60 qw{-jar},
61 $object->{driver_file},
62 0 ▶ @config,
Condition0%0/2
$object->{"command"} //= [$object->{"driver_interpreter"}, @java_opts, "-jar", $object->{"driver_file"}, @config]
l!l
00
MC/DC0%0/1
$object->{"command"} //= [$object->{"driver_interpreter"}, @java_opts, "-jar", $object->{"driver_file"}, @config]
$object->{"command"}
Truth table0%0/2
A
A= $object->{"command"}
Aresult
11
00
63 ];
64 0 return $object;
65 }
66  
67 0 ▶sub _build_config ($self) {
Subroutine _build_config: not called CC=3 SCAR=24.8
68 0 my $dir = File::Spec->catdir( $self->{client_dir}, "perl-client" );
69 0 ▶ make_path($dir) unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
70  
71 0 my $file = File::Spec->catfile( $dir, "config-$self->{port}.toml" );
72 0 ▶ return $file if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 0 0 0
73  
74 # TODO add some self-signed SSL to this
75 0 my $config = <<~EOF;
76 [node]
77 detect-drivers = true
78 [server]
79 allow-cors = true
80 hostname = "localhost"
81 max-threads = 36
82 port = --PORT--
83 [logging]
84 enable = true
85 log-encoding = UTF-8
86 log-file = --REPLACE--
87 plain-logs = true
88 structured-logs = false
89 tracing = true
90 EOF
91  
92 #XXX double escape backslash because windows; like YAML, TOML is a poor choice always
93 #XXX so, you'll die if there are backslashes in your username or homedir choice (lunatic)
94 0 my $log_corrected = $self->{log_file};
95 0 $log_corrected =~ s/\\/\\\\/g;
96  
97 0 $config =~ s/--REPLACE--/\"$log_corrected\"/gm;
98 0 $config =~ s/--PORT--/$self->{port}/gm;
99  
100 0 File::Slurper::write_text( $file, $config );
101 0 return $file;
102 }
103  
104  
105 0 ▶sub find_and_fetch ( $dir, $version = undef, $ua = undef ) {
Subroutine find_and_fetch: not called CC=5 SCAR=34.0
Pod documented
106 0 ▶ make_path($dir) unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
107  
108 0 ▶ $version ||= undef;
Condition0%0/2
$version ||= undef
l!l
00
MC/DC0%0/1
$version ||= undef
$version
Truth table0%0/2
A
A= $version
Aresult
11
00
109  
110 0 my @files = Github::ReleaseFetcher::fetch( $dir, 'SeleniumHQ', 'selenium', qr/\.jar$/, undef, $version, $ua );
111 0 my $latest_jar_at_version = pop(@files);
112 0 my ($actual_version) = $latest_jar_at_version =~ m/-(\d+)\.\d+\.\d.*\.jar$/;
113  
114 0 return ( $latest_jar_at_version, $actual_version );
115 }
116  
117 0 ▶sub find_and_fetch_old_releases ( $dir, $version = '', $ua = '' ) {
Subroutine find_and_fetch_old_releases: not called CC=11 SCAR=48.8
Pod undocumented
118 0 ▶ $ua ||= HTTP::Tiny->new();
Condition0%0/3
$ua ||= "HTTP::Tiny"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$ua ||= "HTTP::Tiny"->new
$ua "HTTP::Tiny"->new
Truth table0%0/3
A ||= B
A= $uaB= "HTTP::Tiny"->new
ABresult
1X1
011
000
119 0 my $res = $ua->get($index);
120 0 ▶ confess "$res->{reason} :\n$res->{content}\n" unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
121 0 my $parsed = XML::LibXML->load_xml( string => $res->{content} );
122  
123 #XXX - XPATH NO WORKY, HURR DURR
124 0 my @files;
125 0 foreach my $element ( $parsed->findnodes('//*') ) {
126 0 my $contents = $element->getChildrenByTagName("Contents");
127 0 ▶ my @candidates = sort { $b cmp $a } grep { m/selenium-server/ && m/\.jar$/ } map { $_->getChildrenByTagName('Key')->to_literal() . ''; } @$contents;
Condition0%0/3
/selenium-server/u && /\.jar$/u
!ll&&!rl&&r
000
MC/DC0%0/2
/selenium-server/u && /\.jar$/u
/selenium-server/u /\.jar$/u
Truth table0%0/3
A && B
A= /selenium-server/uB= /\.jar$/u
ABresult
0X0
100
111
128 0 push( @files, @candidates );
129 }
130  
131 0 ▶ @files = grep { m/\Q$version\E/ } @files if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 0 0 0
132 0 my $jar = shift @files;
133 0 my $url = "$index/$jar";
134  
135 0 ▶ make_path($dir) unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
136 0 my $fname = File::Spec->catfile( $dir, basename($jar) );
137 0 my ($v) = $fname =~ m/-(\d+)\.\d+\.\d.*\.jar$/;
138 0 ▶ return ( $fname, $v ) if -f $fname;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fname 0 0 0
139  
140 0 $res = $ua->mirror( $url, $fname );
141  
142 0 ▶ confess "$res->{reason} :\n$res->{content}\n" unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
143 0 return ( $fname, $v );
144 }
145  
146 1 1;
147  
148 __END__
« lib/Selenium/Specification.pm ↑ Summary lib/Selenium/Client/Driver.pm »