| 1 | package Selenium::CanStartBinary; | ||||||||||||||||||||||||||||||||||||||
| 2 | 10 | $Selenium::CanStartBinary::VERSION = '1.49'; | |||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Teach a WebDriver how to start its own binary aka no JRE! | ||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | use Selenium::CanStartBinary::ProbePort | ||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | qw/find_open_port_above find_open_port probe_port/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Selenium::Firefox::Binary qw/setup_firefox_binary_env/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Selenium::Waiter qw/wait_until/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use constant IS_WIN => $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 10 | requires 'binary'; | |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | 10 | requires 'binary_port'; | |||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 10 | requires '_binary_args'; | |||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | has '_real_binary' => ( | ||||||||||||||||||||||||||||||||||||||
| 27 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 28 | builder => sub { | ||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__real_binary: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ( $self->_is_old_ff ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return $self->firefox_binary; | |||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||
| 34 | else { | ||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return $self->binary; | |||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||
| 38 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | has '_is_old_ff' => ( | ||||||||||||||||||||||||||||||||||||||
| 41 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 42 | builder => sub { | ||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__is_old_ff: not called CC=2 SCAR=17.9
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return $self->isa('Selenium::Firefox') && !$self->marionette_enabled; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->isa('Selenium::Firefox') && !$self->marionette_enabled
$self->isa('Selenium::Firefox') && !$self->marionette_enabled
MC/DC0%0/2
$self->isa('Selenium::Firefox') && !$self->marionette_enabled
$self->isa('Selenium::Firefox')
!$self->marionette_enabled
MC/DC0%0/2
$self->isa('Selenium::Firefox') && !$self->marionette_enabled
$self->isa('Selenium::Firefox')
!$self->marionette_enabled
Truth table0%0/3
A && not(B)
A= $self->isa('Selenium::Firefox')B= !$self->marionette_enabled
Truth table0%0/3
A && not(B)
A= $self->isa('Selenium::Firefox')B= !$self->marionette_enabled
| |||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | has '+port' => ( | ||||||||||||||||||||||||||||||||||||||
| 50 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 51 | builder => sub { | ||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $self->_real_binary ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( $self->fixed_ports ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return find_open_port( $self->binary_port ); | |||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return find_open_port_above( $self->binary_port ); | |||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return 4444; | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||
| 66 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | has 'fixed_ports' => ( | ||||||||||||||||||||||||||||||||||||||
| 70 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | default => sub { 0 } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 72 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | has custom_args => ( | ||||||||||||||||||||||||||||||||||||||
| 76 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 77 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | default => sub { '' } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 79 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | has 'marionette_port' => ( | ||||||||||||||||||||||||||||||||||||||
| 82 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 83 | builder => sub { | ||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_marionette_port: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( $self->_is_old_ff ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( $self->fixed_ports ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return find_open_port( $self->marionette_binary_port ); | |||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return find_open_port_above( $self->marionette_binary_port ); | |||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||
| 98 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | has startup_timeout => ( | ||||||||||||||||||||||||||||||||||||||
| 102 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | default => sub { 10 } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 104 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 10 | has 'binary_mode' => ( | |||||||||||||||||||||||||||||||||||||
| 108 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 109 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||
| 110 | builder => 1, | ||||||||||||||||||||||||||||||||||||||
| 111 | predicate => 1 | ||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | has 'try_binary' => ( | ||||||||||||||||||||||||||||||||||||||
| 115 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 117 | trigger => sub { | ||||||||||||||||||||||||||||||||||||||
| 118 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | $self->binary_mode if $self->try_binary; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||
| 121 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | has 'window_title' => ( | ||||||||||||||||||||||||||||||||||||||
| 125 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 126 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||
| 127 | builder => sub { | ||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my ( undef, undef, $file ) = | |||||||||||||||||||||||||||||||||||||
| 130 | File::Spec->splitpath( $self->_real_binary ); | ||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $port = $self->port; | |||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return $file . ':' . $port; | |||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||
| 135 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||
| 138 | has '_command' => ( | ||||||||||||||||||||||||||||||||||||||
| 139 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 140 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||
| 141 | builder => sub { | ||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return $self->_construct_command; | |||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||
| 145 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | has 'logfile' => ( | ||||||||||||||||||||||||||||||||||||||
| 149 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 150 | default => sub { | ||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return '/nul' if IS_WIN; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return '/dev/null'; | |||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||
| 154 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | # There's a bit of finagling to do to since we can't ensure the | ||||||||||||||||||||||||||||||||||||||
| 159 | # attribute instantiation order. To decide whether we're going into | ||||||||||||||||||||||||||||||||||||||
| 160 | # binary mode, we need the remote_server_addr and port. But, they're | ||||||||||||||||||||||||||||||||||||||
| 161 | # both lazy and only instantiated immediately before S:R:D's | ||||||||||||||||||||||||||||||||||||||
| 162 | # remote_conn attribute. Once remote_conn is set, we can't change it, | ||||||||||||||||||||||||||||||||||||||
| 163 | # so we need the following order: | ||||||||||||||||||||||||||||||||||||||
| 164 | # | ||||||||||||||||||||||||||||||||||||||
| 165 | # parent: remote_server_addr, port | ||||||||||||||||||||||||||||||||||||||
| 166 | # role: binary_mode (aka _build_binary_mode) | ||||||||||||||||||||||||||||||||||||||
| 167 | # parent: remote_conn | ||||||||||||||||||||||||||||||||||||||
| 168 | # | ||||||||||||||||||||||||||||||||||||||
| 169 | # Since we can't force an order, we introduced try_binary which gets | ||||||||||||||||||||||||||||||||||||||
| 170 | # decided during BUILDARGS to tip us off as to whether we should try | ||||||||||||||||||||||||||||||||||||||
| 171 | # binary mode or not. | ||||||||||||||||||||||||||||||||||||||
| 172 | 4 | ▶ | my ( undef, %args ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=13.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | 4 | ▶ | if ( !exists $args{remote_server_addr} && !exists $args{port} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $args{'remote_server_addr'} || exists $args{'port'}
MC/DC0%0/2
exists $args{'remote_server_addr'} || exists $args{'port'}
exists $args{'remote_server_addr'}
exists $args{'port'}
Truth table33%1/3
A || B
A= exists $args{'remote_server_addr'}B= exists $args{'port'}
| |||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $args{try_binary} = 1; | |||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||
| 177 | # Windows may throw a fit about invalid pointers if we try to | ||||||||||||||||||||||||||||||||||||||
| 178 | # connect to localhost instead of 127.1 | ||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $args{remote_server_addr} = '127.0.0.1'; | |||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||
| 182 | 4 | $args{try_binary} = 0; | |||||||||||||||||||||||||||||||||||||
| 183 | 4 | $args{binary_mode} = 0; | |||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | 4 | return {%args}; | |||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||
| 189 | sub _build_binary_mode { | ||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_binary_mode: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | # We don't know what to do without a binary driver to start up | ||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | return unless $self->_real_binary; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||
| 195 | # Either the user asked for 4444, or we couldn't find an open port | ||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $port = $self->port + 0; | |||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | return if $port == 4444; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ( $self->fixed_ports && $port == 0 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->fixed_ports and $port == 0
MC/DC0%0/2
$self->fixed_ports and $port == 0
$self->fixed_ports
$port == 0
Truth table0%0/3
A and B
A= $self->fixed_portsB= $port == 0
| |||||||||||||||||||||||||||||||||||||||
| 199 | 0 | die 'port ' | |||||||||||||||||||||||||||||||||||||
| 200 | . $self->binary_port | ||||||||||||||||||||||||||||||||||||||
| 201 | . ' is not free and have requested fixed ports'; | ||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->_handle_firefox_setup($port); | |||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | 0 | system( $self->_command ); | |||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||
| 208 | my $success = | ||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | wait_until { probe_port($port) } timeout => $self->startup_timeout; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($success) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 211 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||
| 213 | else { | ||||||||||||||||||||||||||||||||||||||
| 214 | 0 | die 'Unable to connect to the ' | |||||||||||||||||||||||||||||||||||||
| 215 | . $self->_real_binary | ||||||||||||||||||||||||||||||||||||||
| 216 | . ' binary on port ' | ||||||||||||||||||||||||||||||||||||||
| 217 | . $port; | ||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | sub _handle_firefox_setup { | ||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | my ( $self, $port ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_firefox_setup: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||
| 224 | # This is a no-op for other browsers | ||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | return unless $self->isa('Selenium::Firefox'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my $user_profile = | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 228 | $self->has_firefox_profile | ||||||||||||||||||||||||||||||||||||||
| 229 | ? $self->firefox_profile | ||||||||||||||||||||||||||||||||||||||
| 230 | : 0; | ||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $profile = | |||||||||||||||||||||||||||||||||||||
| 233 | setup_firefox_binary_env( $port, $self->marionette_port, $user_profile ); | ||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( $self->_is_old_ff ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||
| 237 | # For non-geckodriver/non-marionette, we want to get rid of | ||||||||||||||||||||||||||||||||||||||
| 238 | # the profile so that we don't accidentally zip it and encode | ||||||||||||||||||||||||||||||||||||||
| 239 | # it down the line while Firefox is trying to read from it. | ||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | $self->clear_firefox_profile if $self->has_firefox_profile; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||
| 242 | else { | ||||||||||||||||||||||||||||||||||||||
| 243 | # For geckodriver/marionette, we keep the enhanced profile around because | ||||||||||||||||||||||||||||||||||||||
| 244 | # we need to send it to geckodriver as a zipped b64-encoded | ||||||||||||||||||||||||||||||||||||||
| 245 | # directory. | ||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $self->firefox_profile($profile); | |||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | sub shutdown_binary { | ||||||||||||||||||||||||||||||||||||||
| 251 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
shutdown_binary: called CC=5 SCAR=22.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | return unless $self->auto_close(); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 254 | 4 | ▶ | if ( defined $self->session_id ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $self->quit(); | |||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ▶ | if ( $self->has_binary_mode && $self->binary_mode ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_binary_mode and $self->binary_mode
MC/DC0%0/2
$self->has_binary_mode and $self->binary_mode
$self->has_binary_mode
$self->binary_mode
Truth table33%1/3
A and B
A= $self->has_binary_modeB= $self->binary_mode
| |||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | # Tell the binary itself to shutdown | ||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $port = $self->port; | |||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $ua = $self->ua; | |||||||||||||||||||||||||||||||||||||
| 262 | 0 | $ua->get( 'http://127.0.0.1:' . $port . '/wd/hub/shutdown' ); | |||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||
| 264 | # Close the orphaned command windows on windows | ||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $self->shutdown_windows_binary; | |||||||||||||||||||||||||||||||||||||
| 266 | 0 | $self->shutdown_unix_binary; | |||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||
| 271 | sub shutdown_unix_binary { | ||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
shutdown_unix_binary: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 273 | 0 | if (!IS_WIN) { | |||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $cmd = "lsof -t -i :".$self->port(); | |||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | my ( $pid ) = grep { $_ && $_ ne $$ } split( /\s+/, scalar `$cmd` ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 277 | 0 | print "Killing Driver PID $pid listening on port " | |||||||||||||||||||||||||||||||||||||
| 278 | . $self->port . "...\n"; | ||||||||||||||||||||||||||||||||||||||
| 279 | 0 | eval { kill 'KILL', $pid }; | |||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | warn | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 281 | "Could not kill driver process! you may have to clean up manually." | ||||||||||||||||||||||||||||||||||||||
| 282 | if $@; | ||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | sub shutdown_windows_binary { | ||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
shutdown_windows_binary: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||
| 290 | 0 | if (IS_WIN) { | |||||||||||||||||||||||||||||||||||||
| 291 | if ( $self->_is_old_ff ) { | ||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | # FIXME: Blech, handle a race condition that kills the | ||||||||||||||||||||||||||||||||||||||
| 294 | # driver before it's finished cleaning up its sessions. In | ||||||||||||||||||||||||||||||||||||||
| 295 | # particular, when the perl process ends, it wants to | ||||||||||||||||||||||||||||||||||||||
| 296 | # clean up the temp directory it created for the Firefox | ||||||||||||||||||||||||||||||||||||||
| 297 | # profile. But, if the Firefox process is still running, | ||||||||||||||||||||||||||||||||||||||
| 298 | # it will have a lock on the temp profile directory, and | ||||||||||||||||||||||||||||||||||||||
| 299 | # perl will get upset. This "solution" is _very_ bad. | ||||||||||||||||||||||||||||||||||||||
| 300 | sleep(2); | ||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||
| 302 | # Firefox doesn't have a Driver/Session architecture - the | ||||||||||||||||||||||||||||||||||||||
| 303 | # only thing running is Firefox itself, so there's no | ||||||||||||||||||||||||||||||||||||||
| 304 | # other task to kill. | ||||||||||||||||||||||||||||||||||||||
| 305 | return; | ||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||
| 307 | system( 'taskkill /FI "WINDOWTITLE eq ' | ||||||||||||||||||||||||||||||||||||||
| 308 | . $self->window_title | ||||||||||||||||||||||||||||||||||||||
| 309 | . '" > nul 2>&1' ); | ||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||
| 313 | sub DEMOLISH { | ||||||||||||||||||||||||||||||||||||||
| 314 | 4 | ▶ | my ( $self, $in_gd ) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||
| 316 | # if we're in global destruction, all bets are off. | ||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | return if $in_gd; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 318 | 4 | $self->shutdown_binary; | |||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||
| 321 | sub _construct_command { | ||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_construct_command: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $executable = $self->_real_binary; | |||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||
| 325 | # Executable path names may have spaces | ||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $executable = '"' . $executable . '"'; | |||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | # The different binaries take different arguments for proper setup | ||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $executable .= $self->_binary_args; | |||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ( $self->has_custom_args ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $executable .= ' ' . $self->custom_args; | |||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||
| 334 | # Handle Windows vs Unix discrepancies for invoking shell commands | ||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my ( $prefix, $suffix ) = ( $self->_cmd_prefix, $self->_cmd_suffix ); | |||||||||||||||||||||||||||||||||||||
| 336 | 0 | return join( ' ', ( $prefix, $executable, $suffix ) ); | |||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||
| 339 | sub _cmd_prefix { | ||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmd_prefix: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $prefix = ''; | |||||||||||||||||||||||||||||||||||||
| 343 | 0 | if (IS_WIN) { | |||||||||||||||||||||||||||||||||||||
| 344 | $prefix = 'start "' . $self->window_title . '"'; | ||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||
| 346 | if ( $self->_is_old_ff ) { | ||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||
| 348 | # For older versions of Firefox that run without | ||||||||||||||||||||||||||||||||||||||
| 349 | # marionette, the command we're running actually starts up | ||||||||||||||||||||||||||||||||||||||
| 350 | # the browser itself, so we don't want to minimize it. | ||||||||||||||||||||||||||||||||||||||
| 351 | return $prefix; | ||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||
| 353 | else { | ||||||||||||||||||||||||||||||||||||||
| 354 | # If we're firefox with marionette, or any other browser, | ||||||||||||||||||||||||||||||||||||||
| 355 | # the command we're running is the driver, and we don't | ||||||||||||||||||||||||||||||||||||||
| 356 | # need want the command window in the foreground. | ||||||||||||||||||||||||||||||||||||||
| 357 | return $prefix . ' /MIN '; | ||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||
| 360 | 0 | return $prefix; | |||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||
| 363 | sub _cmd_suffix { | ||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmd_suffix: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 365 | 0 | return " > " . $self->logfile . " 2>&1 " if IS_WIN; | |||||||||||||||||||||||||||||||||||||
| 366 | 0 | return " > " . $self->logfile . " 2>&1 &"; | |||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||
| 370 | 10 | 1; | |||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||
| 372 | __END__ | ||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||
| 374 | =pod | ||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||
| 376 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||
| 378 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||
| 380 | Selenium::CanStartBinary - Teach a WebDriver how to start its own binary aka no JRE! | ||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||
| 382 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||
| 384 | version 1.49 | ||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||
| 386 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||
| 388 | This role takes care of the details for starting up a Webdriver | ||||||||||||||||||||||||||||||||||||||
| 389 | instance. It does not do any downloading or installation of any sort - | ||||||||||||||||||||||||||||||||||||||
| 390 | you're still responsible for obtaining and installing the necessary | ||||||||||||||||||||||||||||||||||||||
| 391 | binaries into your C<$PATH> for this role to find. You may be | ||||||||||||||||||||||||||||||||||||||
| 392 | interested in L<Selenium::Chrome>, L<Selenium::Firefox>, or | ||||||||||||||||||||||||||||||||||||||
| 393 | L<Selenium::PhantomJS> if you're looking for classes that already | ||||||||||||||||||||||||||||||||||||||
| 394 | consume this role. | ||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||
| 396 | The role determines whether or not it should try to do its own magic | ||||||||||||||||||||||||||||||||||||||
| 397 | based on whether the consuming class is instantiated with a | ||||||||||||||||||||||||||||||||||||||
| 398 | C<remote_server_addr> and/or C<port>. | ||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||
| 400 | # We'll start up the Chrome binary for you | ||||||||||||||||||||||||||||||||||||||
| 401 | my $chrome_via_binary = Selenium::Chrome->new; | ||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||
| 403 | # Look for a selenium server running on 4444. | ||||||||||||||||||||||||||||||||||||||
| 404 | my $chrome_via_server = Selenium::Chrome->new( port => 4444 ); | ||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||
| 406 | If they're missing, we assume the user wants to use a webdriver | ||||||||||||||||||||||||||||||||||||||
| 407 | directly and act accordingly. We handle finding the proper associated | ||||||||||||||||||||||||||||||||||||||
| 408 | binary (or you can specify it with L</binary>), figuring out what | ||||||||||||||||||||||||||||||||||||||
| 409 | arguments it wants, setting up any necessary environments, and | ||||||||||||||||||||||||||||||||||||||
| 410 | starting up the binary. | ||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||
| 412 | There's a number of TODOs left over - namely Windows support is | ||||||||||||||||||||||||||||||||||||||
| 413 | severely lacking, and we're pretty naive when we attempt to locate the | ||||||||||||||||||||||||||||||||||||||
| 414 | executables on our own. | ||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||
| 416 | In the following documentation, C<required> refers to when you're | ||||||||||||||||||||||||||||||||||||||
| 417 | consuming the role, not the C<required> when you're instantiating a | ||||||||||||||||||||||||||||||||||||||
| 418 | class that has already consumed the role. | ||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||
| 420 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||
| 422 | =head2 binary | ||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||
| 424 | Required: Specify the path to the executable in question, or the name | ||||||||||||||||||||||||||||||||||||||
| 425 | of the executable for us to find via L<File::Which/which>. | ||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||
| 427 | =head2 binary_port | ||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||
| 429 | Required: Specify a default port that for the webdriver binary to try | ||||||||||||||||||||||||||||||||||||||
| 430 | to bind to. If that port is unavailable, we'll probe above that port | ||||||||||||||||||||||||||||||||||||||
| 431 | until we find a valid one. | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | =head2 _binary_args | ||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||
| 435 | Required: Specify the arguments that the particular binary needs in | ||||||||||||||||||||||||||||||||||||||
| 436 | order to start up correctly. In particular, you may need to tell the | ||||||||||||||||||||||||||||||||||||||
| 437 | binary about the proper port when we start it up, or that it should | ||||||||||||||||||||||||||||||||||||||
| 438 | use a particular prefix to match up with the behavior of the Remote | ||||||||||||||||||||||||||||||||||||||
| 439 | Driver server. | ||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||
| 441 | If your binary doesn't need any arguments, just have the default be an | ||||||||||||||||||||||||||||||||||||||
| 442 | empty string. | ||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||
| 444 | =head2 port | ||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||
| 446 | The role will attempt to determine the proper port for us. Consuming | ||||||||||||||||||||||||||||||||||||||
| 447 | roles should set a default port in L</binary_port> at which we will | ||||||||||||||||||||||||||||||||||||||
| 448 | begin searching for an open port. | ||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||
| 450 | Note that if we cannot locate a suitable L</binary>, port will be set | ||||||||||||||||||||||||||||||||||||||
| 451 | to 4444 so we can attempt to look for a Selenium server at | ||||||||||||||||||||||||||||||||||||||
| 452 | C<127.0.0.1:4444>. | ||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||
| 454 | =head2 fixed_ports | ||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||
| 456 | Optional: By default, if binary_port and marionette_port are not free | ||||||||||||||||||||||||||||||||||||||
| 457 | a higher free port is probed and acquired if possible, until a free one | ||||||||||||||||||||||||||||||||||||||
| 458 | if found or a timeout is exceeded. | ||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||
| 460 | my $driver1 = Selenium::Chrome->new; | ||||||||||||||||||||||||||||||||||||||
| 461 | my $driver2 = Selenium::Chrome->new( port => 1234 ); | ||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||
| 463 | The default behavior can be overridden. In this case, only the default | ||||||||||||||||||||||||||||||||||||||
| 464 | or given binary_port and marionette_port are probed, without probing | ||||||||||||||||||||||||||||||||||||||
| 465 | higher ports. This ensures that either the default or given port will be | ||||||||||||||||||||||||||||||||||||||
| 466 | assigned, or no port will be assigned at all. | ||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||
| 468 | my $driver1 = Selenium::Chrome->new( fixed_ports => 1 ); | ||||||||||||||||||||||||||||||||||||||
| 469 | my $driver2 = Selenium::Chrome->new( port => 1234, fixed_ports => 1); | ||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||
| 471 | =head2 custom_args | ||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||
| 473 | Optional: If you want to pass additional options to the binary when it | ||||||||||||||||||||||||||||||||||||||
| 474 | starts up, you can add that here. For example, if your binary accepts | ||||||||||||||||||||||||||||||||||||||
| 475 | an argument on the command line like C<--log-path=/path/to/log>, and | ||||||||||||||||||||||||||||||||||||||
| 476 | you'd like to specify that the binary uses that option, you could do: | ||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||
| 478 | my $chrome = Selenium::Chrome->new( | ||||||||||||||||||||||||||||||||||||||
| 479 | custom_args => '--log-path=/path/to/log' | ||||||||||||||||||||||||||||||||||||||
| 480 | ); | ||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||
| 482 | To specify multiple arguments, just include them all in the string. | ||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||
| 484 | =head2 startup_timeout | ||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||
| 486 | Optional: you can modify how long we will wait for the binary to start | ||||||||||||||||||||||||||||||||||||||
| 487 | up. By default, we will start the binary and check the intended | ||||||||||||||||||||||||||||||||||||||
| 488 | destination port for 10 seconds before giving up. If the machine | ||||||||||||||||||||||||||||||||||||||
| 489 | you're using to run your browsers is slower or smaller, you may need | ||||||||||||||||||||||||||||||||||||||
| 490 | to increase this timeout. | ||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||
| 492 | The following: | ||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||
| 494 | my $f = Selenium::Firefox->new( | ||||||||||||||||||||||||||||||||||||||
| 495 | startup_timeout => 60 | ||||||||||||||||||||||||||||||||||||||
| 496 | ); | ||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||
| 498 | will wait up to 60 seconds for the firefox binary to respond on the | ||||||||||||||||||||||||||||||||||||||
| 499 | proper port. To use this constructor option, you should specify a time | ||||||||||||||||||||||||||||||||||||||
| 500 | in seconds as an integer, and it will be passed to the arguments | ||||||||||||||||||||||||||||||||||||||
| 501 | section of a L<Selenium::Waiter/wait_until> subroutine call. | ||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||
| 503 | =head2 binary_mode | ||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||
| 505 | Mostly intended for internal use, its builder coordinates all the side | ||||||||||||||||||||||||||||||||||||||
| 506 | effects of interacting with the binary: locating the executable, | ||||||||||||||||||||||||||||||||||||||
| 507 | finding an open port, setting up the environment, shelling out to | ||||||||||||||||||||||||||||||||||||||
| 508 | start the binary, and ensuring that the webdriver is listening on the | ||||||||||||||||||||||||||||||||||||||
| 509 | correct port. | ||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||
| 511 | If all of the above steps pass, it will return truthy after | ||||||||||||||||||||||||||||||||||||||
| 512 | instantiation. If any of them fail, it should return falsy and the | ||||||||||||||||||||||||||||||||||||||
| 513 | class should attempt normal L<Selenium::Remote::Driver> behavior. | ||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||
| 515 | =head2 window_title | ||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||
| 517 | Intended for internal use: this will build us a unique title for the | ||||||||||||||||||||||||||||||||||||||
| 518 | background binary process of the Webdriver. Then, when we're cleaning | ||||||||||||||||||||||||||||||||||||||
| 519 | up, we know what the window title is that we're going to C<taskkill>. | ||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||
| 521 | =head2 command | ||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||
| 523 | Intended for internal use: this read-only attribute is built by us, | ||||||||||||||||||||||||||||||||||||||
| 524 | but it can be useful after instantiation to see exactly what command | ||||||||||||||||||||||||||||||||||||||
| 525 | was run to start the webdriver server. | ||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||
| 527 | my $f = Selenium::Firefox->new; | ||||||||||||||||||||||||||||||||||||||
| 528 | say $f->_command; | ||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||
| 530 | =head2 logfile | ||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||
| 532 | Normally we log what occurs in the driver to /dev/null (or /nul on windows). | ||||||||||||||||||||||||||||||||||||||
| 533 | Setting this will redirect it to the provided file. | ||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||
| 535 | =for Pod::Coverage *EVERYTHING* | ||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||
| 537 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||
| 539 | Selenium::Chrome | ||||||||||||||||||||||||||||||||||||||
| 540 | Selenium::Firefox | ||||||||||||||||||||||||||||||||||||||
| 541 | Selenium::PhantomJS | ||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||
| 543 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||
| 545 | Current Maintainers: | ||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||
| 547 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||
| 549 | =item * | ||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||
| 551 | George S. Baugh <george@troglodyne.net> | ||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||
| 553 | =back | ||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||
| 555 | Previous maintainers: | ||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||
| 557 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||
| 559 | =item * | ||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||
| 561 | Daniel Gempesaw <gempesaw@gmail.com> | ||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||
| 563 | =item * | ||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||
| 565 | Emmanuel Peroumalnaïk <peroumalnaik.emmanuel@gmail.com> | ||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||
| 567 | =item * | ||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||
| 569 | Luke Closs <cpan@5thplane.com> | ||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||
| 571 | =item * | ||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||
| 573 | Mark Stosberg <mark@stosberg.com> | ||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||
| 575 | =back | ||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||
| 577 | Original authors: | ||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||
| 579 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||
| 581 | =item * | ||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||
| 583 | Aditya Ivaturi <ivaturi@gmail.com> | ||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||
| 585 | =back | ||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||
| 587 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||
| 589 | Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child | ||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||
| 591 | Copyright (c) 2014-2017 Daniel Gempesaw | ||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||
| 593 | Copyright (c) 2018-2021 George S. Baugh | ||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||
| 595 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||
| 596 | you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||
| 597 | You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||
| 599 | http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||
| 601 | Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||
| 602 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||
| 603 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||
| 604 | See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||
| 605 | limitations under the License. | ||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||
| 607 | =cut | ||||||||||||||||||||||||||||||||||||||