Browse Source

Encode the Firefox profile during binary startup

With the introduction of the geckodriver binary and FF48, the correct
way to start up Firefox is to pass an encoded profile instead of setting
XRE_PROFILE_PATH.
Daniel Gempesaw 9 years ago
parent
commit
a5ef784290
3 changed files with 13 additions and 5 deletions
  1. 5 2
      lib/Selenium/CanStartBinary.pm
  2. 7 3
      lib/Selenium/Remote/Driver.pm
  3. 1 0
      t/CanStartBinary.t

+ 5 - 2
lib/Selenium/CanStartBinary.pm

@@ -285,10 +285,13 @@ sub _build_binary_mode {
 
 
         if ($self->has_firefox_profile) {
         if ($self->has_firefox_profile) {
             push @args, $self->firefox_profile;
             push @args, $self->firefox_profile;
-            $self->clear_firefox_profile;
         }
         }
 
 
-        setup_firefox_binary_env(@args);
+        my $profile = setup_firefox_binary_env(@args);
+        # For geckodriver, setting env variable XRE_PROFILE_PATH does
+        # not seem to work anymore. Instead, geckodriver accepts an
+        # encoded firefox profile, so we need to set it on the Driver.
+        $self->firefox_profile($profile);
     }
     }
 
 
     my $command = $self->_construct_command;
     my $command = $self->_construct_command;

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

@@ -486,8 +486,7 @@ has 'firefox_profile' => (
 
 
         return $profile;
         return $profile;
     },
     },
-    predicate => 'has_firefox_profile',
-    clearer => 1
+    predicate => 'has_firefox_profile'
 );
 );
 
 
 has 'desired_capabilities' => (
 has 'desired_capabilities' => (
@@ -674,7 +673,12 @@ sub new_desired_session {
 
 
 sub _request_new_session {
 sub _request_new_session {
     my ( $self, $args ) = @_;
     my ( $self, $args ) = @_;
-    $self->remote_conn->check_status();
+
+    # geckodriver has not yet implemented the GET /status endpoint
+    # https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver/status
+    if (! $self->isa('Selenium::Firefox')) {
+        $self->remote_conn->check_status();
+    }
     # command => 'newSession' to fool the tests of commands implemented
     # command => 'newSession' to fool the tests of commands implemented
     # TODO: rewrite the testing better, this is so fragile.
     # TODO: rewrite the testing better, this is so fragile.
     my $resource_new_session = {
     my $resource_new_session = {

+ 1 - 0
t/CanStartBinary.t

@@ -79,6 +79,7 @@ FIREFOX: {
         my $firefox = Selenium::Firefox->new;
         my $firefox = Selenium::Firefox->new;
         isnt( $firefox->port, 4444, 'firefox can start up its own binary');
         isnt( $firefox->port, 4444, 'firefox can start up its own binary');
         ok( Selenium::CanStartBinary::probe_port( $firefox->port ), 'the firefox binary is listening on its port');
         ok( Selenium::CanStartBinary::probe_port( $firefox->port ), 'the firefox binary is listening on its port');
+        $firefox->shutdown_binary;
 
 
         my $firefox_marionette = Selenium::Firefox->new(
         my $firefox_marionette = Selenium::Firefox->new(
             marionette_enabled => 1
             marionette_enabled => 1