ソースを参照

Promote firefox_profile to init hash argument

I struggled with this for a few days - should the initiation look like

    my $fp_driver = Selenium::Remote::Driver->new(firefox_profile => $fp);

or

    my $fp_driver = Selenium::Remote::Driver->new(extra_capabilities => {
        firefox_profile => $fp
    });

My issue is I'm not sure what the 'extra' in 'extra_capabilities' really
refers to. This leads to, in practice, some confusion about what
arguments go where.

The disadvantage of having it as a primary arg is that it adds to the
confusion of what extra_capabilities is for in the first place. The
advantage is that it will fit into the future way that is mentioned in
issue #110 where everything in the init hash makes it into the
desiredCapabilities object in the eventual POST to /session.

It is probably internally consistent to have it in the
extra_capabilities hash considering the current implementation in 0.18,
but I was reluctant to do that because it wouldn't reflect the new API
that should supercede extra_capabilities.

I decided to promote it to a top level argument in light of the planned
changes from #110.
Daniel Gempesaw 11 年 前
コミット
1bed10d143
3 ファイル変更8 行追加17 行削除
  1. 1 9
      lib/Selenium/Remote/Driver.pm
  2. 4 8
      t/Firefox-Profile.t
  3. 3 0
      t/bin/generate-recordings.pl

+ 1 - 9
lib/Selenium/Remote/Driver.pm

@@ -278,19 +278,11 @@ has 'proxy' => (
 
 has 'extra_capabilities' => (
     is      => 'rw',
-    default => sub { {} },
-    trigger => sub {
-        my ($self, $extra_capabilities) = @_;
-
-        if (defined $extra_capabilities->{firefox_profile} && !$self->has_firefox_profile) {
-            $self->firefox_profile($extra_capabilities->{firefox_profile});
-        }
-    }
+    default => sub { {} }
 );
 
 has 'firefox_profile' => (
     is => 'rw',
-    init_arg => undef,
     coerce => sub {
         my $profile = shift;
         unless (Scalar::Util::blessed($profile)

+ 4 - 8
t/Firefox-Profile.t

@@ -40,7 +40,7 @@ if (!$record && !(-e "t/mock-recordings/$mock_file"))
 t::lib::MockSeleniumWebDriver::register($record,"t/mock-recordings/$mock_file");
 
 CUSTOM_EXTENSION_LOADED: {
-    my $profile = Selenium::Remote::Driver::Firefox::Profile->new();
+    my $profile = Selenium::Remote::Driver::Firefox::Profile->new;
 
     my $website = 'http://localhost:63636';
     $profile->set_preferences(
@@ -60,9 +60,7 @@ CUSTOM_EXTENSION_LOADED: {
     $profile->add_extension('t/www/redisplay.xpi');
 
     my $driver = Selenium::Remote::Driver->new(
-        extra_capabilities => {
-            firefox_profile => $profile
-        }
+        firefox_profile => $profile
     );
 
     ok(defined $driver, "made a driver without dying");
@@ -127,7 +125,7 @@ PREFERENCES_FORMATTING: {
 }
 
 CROAKING: {
-    my $profile = Selenium::Remote::Driver::Firefox::Profile->new();
+    my $profile = Selenium::Remote::Driver::Firefox::Profile->new;
     {
         eval {
             $profile->add_extension('00-load.t');
@@ -146,9 +144,7 @@ CROAKING: {
     {
         eval {
             my $croakingDriver = Selenium::Remote::Driver->new(
-                extra_capabilities => {
-                    firefox_profile => 'clearly invalid!'
-                }
+                firefox_profile => 'clearly invalid!'
             );
         };
         ok ($@ =~ /coercion.*failed/, "caught invalid extension in driver constructor");

+ 3 - 0
t/bin/generate-recordings.pl

@@ -9,6 +9,9 @@ unless (-d "t" && -f "dist.ini" && -f "t/01-driver.t" && -f "t/02-webelement.t")
 
 startServer();
 
+print 'Cleaning...and building...
+';
+print `dzil clean`;
 print `dzil build`;
 
 if ($^O eq 'linux') {