Ver Fonte

Enable CLI arguments to be passed in Binary role

Fix #252.
Daniel Gempesaw há 9 anos atrás
pai
commit
76b36af97f

+ 24 - 0
lib/Selenium/CanStartBinary.pm

@@ -121,6 +121,27 @@ has '+port' => (
     }
 );
 
+=attr custom_args
+
+Optional: If you want to pass additional options to the binary when it
+starts up, you can add that here. For example, if your binary accepts
+an argument on the command line like C<--log-path=/path/to/log>, and
+you'd like to specify that the binary uses that option, you could do:
+
+    my $chrome = Selenium::Chrome->new(
+        custom_args => '--log-path=/path/to/log'
+    );
+
+To specify multiple arguments, just include them all in the string.
+
+=cut
+
+has custom_args => (
+    is => 'lazy',
+    predicate => 1,
+    default => sub { '' }
+);
+
 =attr startup_timeout
 
 Optional: you can modify how long we will wait for the binary to start
@@ -323,6 +344,9 @@ sub _construct_command {
 
     # The different binaries take different arguments for proper setup
     $executable .= $self->_binary_args;
+    if ($self->has_custom_args) {
+        $executable .= ' ' . $self->custom_args;
+    }
 
     # Handle Windows vs Unix discrepancies for invoking shell commands
     my ($prefix, $suffix) = ($self->_cmd_prefix, $self->_cmd_suffix);

+ 6 - 0
lib/Selenium/Chrome.pm

@@ -82,6 +82,12 @@ has '_binary_args' => (
 
 with 'Selenium::CanStartBinary';
 
+=attr custom_args
+
+Optional: specify any additional command line arguments you'd like
+invoked during the binary startup. See
+L<Selenium::CanStartBinary/custom_args> for more information.
+
 =attr startup_timeout
 
 Optional: specify how long to wait for the binary to start itself and

+ 6 - 0
lib/Selenium/Firefox.pm

@@ -86,6 +86,12 @@ has '+wd_context_prefix' => (
 
 with 'Selenium::CanStartBinary';
 
+=attr custom_args
+
+Optional: specify any additional command line arguments you'd like
+invoked during the binary startup. See
+L<Selenium::CanStartBinary/custom_args> for more information.
+
 =attr startup_timeout
 
 Optional: specify how long to wait for the binary to start itself and

+ 6 - 0
lib/Selenium/PhantomJS.pm

@@ -92,6 +92,12 @@ has '_binary_args' => (
 
 with 'Selenium::CanStartBinary';
 
+=attr custom_args
+
+Optional: specify any additional command line arguments you'd like
+invoked during the binary startup. See
+L<Selenium::CanStartBinary/custom_args> for more information.
+
 =attr startup_timeout
 
 Optional: specify how long to wait for the binary to start itself and

+ 5 - 1
t/CanStartBinary.t

@@ -53,7 +53,11 @@ CHROME: {
         skip 'Chrome binary not found in path', 3
           unless $has_chromedriver;
 
-        my $chrome = Selenium::Chrome->new;
+        my $chrome = Selenium::Chrome->new(
+            custom_args => ' --fake-arg'
+        );
+
+        like( $chrome->_construct_command, qr/--fake-arg/, 'can pass custom args');
         ok( $chrome->browser_name eq 'chrome', 'convenience chrome is okay' );
         isnt( $chrome->port, 4444, 'chrome can start up its own binary' );
         like( $chrome->_binary_args, qr/--url-base=wd\/hub/, 'chrome has correct webdriver context' );