Bladeren bron

Look for Firefox in Program Files on Windows

Daniel Gempesaw 10 jaren geleden
bovenliggende
commit
7f646b01d7
3 gewijzigde bestanden met toevoegingen van 18 en 6 verwijderingen
  1. 6 3
      lib/Selenium/CanStartBinary.pm
  2. 12 0
      lib/Selenium/Firefox/Binary.pm
  3. 0 3
      t/CanStartBinary.t

+ 6 - 3
lib/Selenium/CanStartBinary.pm

@@ -187,19 +187,22 @@ sub _find_executable {
 sub _construct_command {
     my ($self, $executable, $port) = @_;
 
+    # Handle spaces in executable path names
+    $executable = '"' . $executable . '"';
+
     my %args;
-    if ($executable =~ /chromedriver(\.exe)?$/i) {
+    if ($executable =~ /chromedriver(\.exe)?"$/i) {
         %args = (
             port => $port,
             'url-base' => 'wd/hub'
         );
     }
-    elsif ($executable =~ /phantomjs(\.exe)?$/i) {
+    elsif ($executable =~ /phantomjs(\.exe)?"$/i) {
         %args = (
             webdriver => '127.0.0.1:' . $port
         );
     }
-    elsif ($executable =~ /firefox/i) {
+    elsif ($executable =~ /firefox(-bin|\.exe)"$/i) {
         $executable .= ' -no-remote ';
     }
 

+ 12 - 0
lib/Selenium/Firefox/Binary.pm

@@ -10,6 +10,18 @@ our @EXPORT_OK = qw/firefox_path setup_firefox_binary_env/;
 
 sub _firefox_windows_path {
     # TODO: make this slightly less dumb
+    my @program_files = (
+        $ENV{PROGRAMFILES} // 'C:\Program Files',
+        $ENV{'PROGRAMFILES(X86)'} // 'C:\Program Files (x86)',
+    );
+
+    foreach (@program_files) {
+        my $binary_path = $_ . '\Mozilla Firefox\firefox.exe';
+        return $binary_path if -x $binary_path;
+    }
+
+    # Fall back to a completely naive strategy
+    warn q/We couldn't find a viable firefox.EXE; you may want to specify it via the binary attribute./;
     return which('firefox');
 }
 

+ 0 - 3
t/CanStartBinary.t

@@ -70,9 +70,6 @@ CHROME: {
 }
 
 FIREFOX: {
-    my $command = Selenium::CanStartBinary->_construct_command('firefox', 1234);
-    ok($command =~ /firefox -no-remote/, 'firefox command has proper args');
-
   SKIP: {
         skip 'Firefox will not start up on UNIX without a display', 3
           if ($^O ne 'MSWin32' && ! $ENV{DISPLAY});