| 1 | package Selenium::Firefox::Binary; | ||||||||||||||||||||||||||||
| 2 | 12 | $Selenium::Firefox::Binary::VERSION = '1.49'; | |||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Subroutines for locating and properly initializing the Firefox Binary | ||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use File::Which qw/which/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Selenium::Firefox::Profile; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 12 | require Exporter; | |||||||||||||||||||||||||||
| 11 | 12 | our @ISA = qw/Exporter/; | |||||||||||||||||||||||||||
| 12 | 12 | our @EXPORT_OK = qw/firefox_path setup_firefox_binary_env/; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub _firefox_windows_path { | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # TODO: make this slightly less dumb | ||||||||||||||||||||||||||||
| 17 | my @program_files = ( | ||||||||||||||||||||||||||||
| 18 | $ENV{PROGRAMFILES} // 'C:\Program Files', | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $ENV{'PROGRAMFILES(X86)'} // 'C:\Program Files (x86)', | ||||||||||||||||||||||||||
|
Subroutine
_firefox_windows_path: not called CC=5 SCAR=34.0
Condition0%0/4
$ENV{"PROGRAMFILES"} // "C:\\Program Files"
$ENV{"PROGRAMFILES(X86)"} // "C:\\Program Files (x86)"
MC/DC0%0/1
$ENV{"PROGRAMFILES"} // "C:\\Program Files"
$ENV{"PROGRAMFILES"}
MC/DC0%0/1
$ENV{"PROGRAMFILES(X86)"} // "C:\\Program Files (x86)"
$ENV{"PROGRAMFILES(X86)"}
Truth table0%0/2
A
A= $ENV{"PROGRAMFILES"}
Truth table0%0/2
A
A= $ENV{"PROGRAMFILES(X86)"}
| |||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | foreach (@program_files) { | |||||||||||||||||||||||||||
| 23 | 0 | my $binary_path = $_ . '\Mozilla Firefox\firefox.exe'; | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $binary_path if -x $binary_path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Fall back to a completely naive strategy | ||||||||||||||||||||||||||||
| 28 | warn | ||||||||||||||||||||||||||||
| 29 | 0 | q/We couldn't find a viable firefox.EXE; you may want to specify it via the binary attribute./; | |||||||||||||||||||||||||||
| 30 | 0 | return which('firefox'); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub _firefox_darwin_path { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $default_firefox = | ||||||||||||||||||||||||||
|
Subroutine
_firefox_darwin_path: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 35 | '/Applications/Firefox.app/Contents/MacOS/firefox-bin'; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( -e $default_firefox && -x $default_firefox ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $default_firefox and -x $default_firefox
MC/DC0%0/2
-e $default_firefox and -x $default_firefox
-e $default_firefox
-x $default_firefox
Truth table0%0/3
A and B
A= -e $default_firefoxB= -x $default_firefox
| |||||||||||||||||||||||||||||
| 38 | 0 | return $default_firefox; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||
| 41 | 0 | return which('firefox-bin'); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub _firefox_unix_path { | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # TODO: maybe which('firefox3'), which('firefox2') ? | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return which('firefox') || '/usr/bin/firefox'; | ||||||||||||||||||||||||||
|
Subroutine
_firefox_unix_path: not called CC=2 SCAR=17.9
Condition0%0/2
which('firefox') || '/usr/bin/firefox'
MC/DC0%0/1
which('firefox') || '/usr/bin/firefox'
which('firefox')
Truth table0%0/2
A
A= which('firefox')
| |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub firefox_path { | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $path; | ||||||||||||||||||||||||||
|
Subroutine
firefox_path: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 55 | 0 | $path = _firefox_windows_path(); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | elsif ( $^O eq 'darwin' ) { | ||||||||||||||||||||||||||||
| 58 | 0 | $path = _firefox_darwin_path(); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 0 | $path = _firefox_unix_path; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( not -x $path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | die $path . ' is not an executable file.'; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return $path; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # We want the profile to persist to the end of the session, not just | ||||||||||||||||||||||||||||
| 73 | # the end of this function. | ||||||||||||||||||||||||||||
| 74 | 12 | my $profile; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub setup_firefox_binary_env { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my ( $port, $marionette_port, $caller_profile ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
setup_firefox_binary_env: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $profile = $caller_profile || Selenium::Firefox::Profile->new; | ||||||||||||||||||||||||||
|
Condition0%0/3
$caller_profile || 'Selenium::Firefox::Profile'->new
MC/DC0%0/2
$caller_profile || 'Selenium::Firefox::Profile'->new
$caller_profile
'Selenium::Firefox::Profile'->new
Truth table0%0/3
A || B
A= $caller_profileB= 'Selenium::Firefox::Profile'->new
| |||||||||||||||||||||||||||||
| 80 | 0 | $profile->add_webdriver( $port, $marionette_port ); | |||||||||||||||||||||||||||
| 81 | 0 | $profile->add_marionette($marionette_port); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # For non-geckodriver/marionette startup, we instruct Firefox to | ||||||||||||||||||||||||||||
| 84 | # use the profile by specifying the appropriate environment | ||||||||||||||||||||||||||||
| 85 | # variables for it to hook onto. | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( !$marionette_port ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | $ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk; | |||||||||||||||||||||||||||
| 88 | 0 | $ENV{'MOZ_NO_REMOTE'} = '1'; # able to launch multiple instances | |||||||||||||||||||||||||||
| 89 | 0 | $ENV{'MOZ_CRASHREPORTER_DISABLE'} = '1'; # disable breakpad | |||||||||||||||||||||||||||
| 90 | 0 | $ENV{'NO_EM_RESTART'} = | |||||||||||||||||||||||||||
| 91 | '1'; # prevent the binary from detaching from the console.log | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||
| 94 | # In case the user created an old Firefox, which would've set | ||||||||||||||||||||||||||||
| 95 | # those ENV variables, and then wanted to create a new Firefox | ||||||||||||||||||||||||||||
| 96 | # afterwards, the env variables would still be around, and the | ||||||||||||||||||||||||||||
| 97 | # new Firefox would respect the XRE_PROFILE_PATH and try to | ||||||||||||||||||||||||||||
| 98 | # load it in the new geckodriver Firefox, which would cause an | ||||||||||||||||||||||||||||
| 99 | # extension compatibility check | ||||||||||||||||||||||||||||
| 100 | 0 | my @env_vars = qw/ | |||||||||||||||||||||||||||
| 101 | XRE_PROFILE_PATH | ||||||||||||||||||||||||||||
| 102 | MOZ_NO_REMOTE | ||||||||||||||||||||||||||||
| 103 | MOZ_CRASHREPORTER_DISABLE | ||||||||||||||||||||||||||||
| 104 | NO_EM_RESTART | ||||||||||||||||||||||||||||
| 105 | /; | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | foreach (@env_vars) { | |||||||||||||||||||||||||||
| 108 | 0 | delete $ENV{$_}; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | return $profile; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 12 | 1; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =pod | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head1 NAME | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Selenium::Firefox::Binary - Subroutines for locating and properly initializing the Firefox Binary | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 VERSION | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | version 1.49 | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head1 SUBROUTINES | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head2 firefox_path | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Return the path to the firefox binary on your system. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head2 setup_firefox_binary_env | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Sets various environment variables to make firefox work correctly with webDriver. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Current Maintainers: | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =over 4 | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item * | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | George S. Baugh <george@troglodyne.net> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =back | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Previous maintainers: | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =over 4 | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =item * | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | Daniel Gempesaw <gempesaw@gmail.com> | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =item * | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Emmanuel Peroumalnaïk <peroumalnaik.emmanuel@gmail.com> | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =item * | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Luke Closs <cpan@5thplane.com> | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =item * | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Mark Stosberg <mark@stosberg.com> | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =back | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Original authors: | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =over 4 | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =item * | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Aditya Ivaturi <ivaturi@gmail.com> | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =back | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Copyright (c) 2014-2017 Daniel Gempesaw | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Copyright (c) 2018-2021 George S. Baugh | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||
| 194 | you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||
| 195 | You may obtain a copy of the License at | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||
| 200 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||
| 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||
| 202 | See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||
| 203 | limitations under the License. | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =cut | ||||||||||||||||||||||||||||