Forráskód Böngészése

Check for user specified binary during executable resolution

Daniel Gempesaw 10 éve
szülő
commit
d990e5b7a3

+ 14 - 13
lib/Selenium/CanStartBinary.pm

@@ -107,10 +107,7 @@ sub BUILDARGS {
 sub _build_binary_mode {
     my ($self) = @_;
 
-    my $port = $self->start_binary_on_port(
-        $self->binary_name,
-        $self->binary_port
-    );
+    my $port = $self->start_binary_on_port;
     $self->port($port);
     return 1;
 }
@@ -126,11 +123,12 @@ sub probe_port {
 }
 
 sub start_binary_on_port {
-    my ($self, $process, $port) = @_;
+    my ($self) = @_;
 
-    my $executable = $self->_find_executable($process);
-    $port = _find_open_port_above($port);
-    if ($process eq 'firefox') {
+    my $executable = $self->_find_executable;
+    my $port = _find_open_port_above($self->binary_port);
+
+    if (ref($self) eq 'Selenium::Firefox') {
         setup_firefox_binary_env($port);
     }
     my $command = _construct_command($executable, $port);
@@ -157,17 +155,20 @@ sub shutdown_binary {
 }
 
 sub _find_executable {
-    my ($self, $binary) = @_;
+    my ($self) = @_;
 
-    if ($self->has_binary_path) {
-        if (-x $self->binary_path) {
-            return $self->binary_path;
+    # If the user specified the full path to the binary, we don't have
+    # any work to do.
+    if ($self->has_binary) {
+        if (-x abs_path($self->binary)) {
+            return abs_path($self->binary);
         }
         else {
-            die 'The binary at "' . $self->binary_path . '" is not executable. Fix the path or chmod +x it as needed.';
+            die 'The binary at ' . $self->binary . ' is not executable. Choose the correct file or chmod +x it as needed.';
         }
     }
 
+    my $binary = $self->binary;
     if ($binary eq 'firefox') {
         return firefox_path();
     }

+ 1 - 0
lib/Selenium/Chrome.pm

@@ -44,6 +44,7 @@ has '+port' => (
 has 'binary' => (
     is => 'lazy',
     default => sub { 'chromedriver' },
+    predicate => 1
 );
 
 has 'binary_port' => (

+ 1 - 0
lib/Selenium/Firefox.pm

@@ -44,6 +44,7 @@ has '+port' => (
 has 'binary' => (
     is => 'lazy',
     default => sub { 'firefox' },
+    predicate => 1
 );
 
 has 'binary_port' => (

+ 1 - 0
lib/Selenium/PhantomJS.pm

@@ -45,6 +45,7 @@ has '+port' => (
 has 'binary' => (
     is => 'lazy',
     default => sub { 'phantomjs' },
+    predicate => 1
 );
 
 has 'binary_port' => (