Explorar o código

Respect user's firefox profile when using Selenium::Firefox

Daniel Gempesaw %!s(int64=10) %!d(string=hai) anos
pai
achega
c9296796f5

+ 7 - 1
lib/Selenium/CanStartBinary.pm

@@ -216,7 +216,13 @@ sub _build_binary_mode {
     return if $port == 4444;
     return if $port == 4444;
 
 
     if ($self->isa('Selenium::Firefox')) {
     if ($self->isa('Selenium::Firefox')) {
-        setup_firefox_binary_env($port);
+        my @args = ($port);
+
+        if ($self->has_firefox_profile) {
+            push @args, $self->firefox_profile;
+        }
+
+        setup_firefox_binary_env(@args);
     }
     }
 
 
     my $command = $self->_construct_command;
     my $command = $self->_construct_command;

+ 2 - 3
lib/Selenium/Firefox/Binary.pm

@@ -64,10 +64,9 @@ sub firefox_path {
 # the end of this function.
 # the end of this function.
 my $profile;
 my $profile;
 sub setup_firefox_binary_env {
 sub setup_firefox_binary_env {
-    my ($port) = @_;
+    my ($port, $caller_profile) = @_;
 
 
-    # TODO: respect the user's profile instead of overwriting it
-    $profile = Selenium::Firefox::Profile->new;
+    $profile = $caller_profile || Selenium::Firefox::Profile->new;
     $profile->add_webdriver($port);
     $profile->add_webdriver($port);
 
 
     $ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk;
     $ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk;

+ 2 - 3
lib/Selenium/Remote/Driver.pm

@@ -220,7 +220,6 @@ you please.
 =head2 new_from_caps
 =head2 new_from_caps
 
 
  Description:
  Description:
-
     For experienced users who want complete control over the desired
     For experienced users who want complete control over the desired
     capabilities, use this alternative constructor along with the
     capabilities, use this alternative constructor along with the
     C<desired_capabilities> hash key in the init hash. Unlike "new",
     C<desired_capabilities> hash key in the init hash. Unlike "new",
@@ -406,7 +405,7 @@ has 'firefox_profile' => (
             croak "firefox_profile should be a Selenium::Firefox::Profile\n";
             croak "firefox_profile should be a Selenium::Firefox::Profile\n";
         }
         }
 
 
-        return $profile->_encode;
+        return $profile;
     },
     },
     predicate => 'has_firefox_profile'
     predicate => 'has_firefox_profile'
 );
 );
@@ -554,7 +553,7 @@ sub new_session {
 
 
     if ($args->{desiredCapabilities}->{browserName} =~ /firefox/i
     if ($args->{desiredCapabilities}->{browserName} =~ /firefox/i
           && $self->has_firefox_profile) {
           && $self->has_firefox_profile) {
-        $args->{desiredCapabilities}->{firefox_profile} = $self->firefox_profile;
+        $args->{desiredCapabilities}->{firefox_profile} = $self->firefox_profile->_encode;
     }
     }
 
 
     $self->_request_new_session($args);
     $self->_request_new_session($args);