Pārlūkot izejas kodu

Fix to #363: Pass caps to chrome/firefox correctly, add ability to do that

Every driver has to be special

Also Update CHANGES
George S. Baugh 8 gadi atpakaļ
vecāks
revīzija
aa8eba973b

+ 7 - 1
Changes

@@ -1,6 +1,12 @@
 Revision history for Selenium-Remote-Driver
 
-1.21   08-??-27 TEODESIAN
+1.22   01-25-2018 TEODESIAN
+        [BUG FIXES]
+        - Fix issue where is_enabled() polyfill on WD3 servers was checking the wrong attribute.
+        - Fix issue where Firefox/Chrome capabilities were not correctly passed
+        - Make some JS polyfill failures non-fatal
+
+1.21   01-19-2018 TEODESIAN
         [NEW MAINTAINER]
         - George S. Baugh (@teodesian on github, TEODESIAN on CPAN) is now the maintainer.
 

+ 3 - 0
at/sanity-chrome.test

@@ -19,6 +19,9 @@ my $driver = Selenium::Remote::Driver->new(
     port => 4444,
     browser_name => 'chrome',
     accept_ssl_certs => 1,
+    extra_capabilities => {
+        args => ['start-maximized'],
+    },
 );
 isa_ok($driver,'Selenium::Remote::Driver',"Can get new S::R::D with WebDriver3");
 

+ 5 - 0
at/sanity.test

@@ -14,13 +14,18 @@ use Selenium::Remote::WDKeys;
 #TODO: cover new_from_caps
 #TODO: Selenium::Firefox::Profile usage
 
+$Selenium::Remote::Driver::FORCE_WD3 = 1;
 my $driver = Selenium::Remote::Driver->new(
     remote_server_addr => 'localhost',
     port => 4444,
     browser_name => 'firefox',
     accept_ssl_certs => 1,
+    extra_capabilities => {
+        log => { level => 'trace' },
+    },
 );
 isa_ok($driver,'Selenium::Remote::Driver',"Can get new S::R::D with WebDriver3");
+die;
 
 $driver->debug_on();
 

+ 30 - 6
lib/Selenium/Remote/Driver.pm

@@ -48,6 +48,7 @@ use constant FINDERS => {
 };
 
 our $FORCE_WD2 = 0;
+our $FORCE_WD3 = 0;
 our %CURRENT_ACTION_CHAIN = ( actions => [] );
 
 =for Pod::Coverage BUILD
@@ -214,6 +215,24 @@ any new browser/driver will likely have problems if it's not listed above.
 There is also a 'legacy.test' file available to run against old browsers/selenium (2.x servers, pre geckodriver).
 This should only be used to verify backwards-compatibility has not been broken.
 
+=head2 Firefox Notes
+
+If you are intending to pass extra_capabilities to firefox on a WD3 enabled server with geckodriver, you MUST do the following:
+
+   $Selenium::Remote::Driver::FORCE_WD3=1;
+
+This is because the gecko driver prefers legacy capabilities, both of which are normally passed for compatibility reasons.
+
+=head2 Chrome Notes
+
+extra_capabilities may? not work, because chromedriver considers the chromeOptions parameter to be invalid, despite it's documentation here:
+
+    https://sites.google.com/a/chromium.org/chromedriver/capabilities
+
+Other bindings get around this by just using the 'old' way of passing desired capabilities.  You can do this too like so:
+
+    $Selenium::Remote::Driver::FORCE_WD2=1;
+
 =head1 CONSTRUCTOR
 
 =head2 new
@@ -832,14 +851,16 @@ sub new_session {
     $extra_capabilities ||= {};
     my $args = {
         'desiredCapabilities' => {
-            'browserName'       => $self->browser_name,
-            'platform'          => $self->platform,
-            'javascriptEnabled' => $self->javascript,
-            'version'           => $self->version,
-            'acceptSslCerts'    => $self->accept_ssl_certs,
+            'browserName'        => $self->browser_name,
+            'platform'           => $self->platform,
+            'javascriptEnabled'  => $self->javascript,
+            'version'            => $self->version,
+            'acceptSslCerts'     => $self->accept_ssl_certs,
             %$extra_capabilities,
         },
     };
+    $args->{'extra_capabilities'} = \%$extra_capabilities unless $FORCE_WD2;
+
 
     if ( defined $self->proxy ) {
         $args->{desiredCapabilities}->{proxy} = $self->proxy;
@@ -878,11 +899,13 @@ sub _request_new_session {
     foreach my $cap (keys(%{$args->{capabilities}->{alwaysMatch} })) {
         #Handle browser specific capabilities
         if (exists($args->{desiredCapabilities}->{browserName}) && $cap eq 'extra_capabilities') {
+
             if (exists $args->{capabilities}->{alwaysMatch}->{'moz:firefoxOptions'}->{args}) {
                 $args->{capabilities}->{alwaysMatch}->{$cap}->{args} = $args->{capabilities}->{alwaysMatch}->{'moz:firefoxOptions'}->{args};
             }
             $args->{capabilities}->{alwaysMatch}->{'moz:firefoxOptions'} = $args->{capabilities}->{alwaysMatch}->{$cap} if $args->{desiredCapabilities}->{browserName} eq 'firefox';
-            $args->{capabilities}->{alwaysMatch}->{'chromeOptions'}      = $args->{capabilities}->{alwaysMatch}->{$cap} if $args->{desiredCapabilities}->{browserName} eq 'chrome';
+            #XXX the chrome documentation is lies, you can't do this yet
+            #$args->{capabilities}->{alwaysMatch}->{'chromeOptions'}      = $args->{capabilities}->{alwaysMatch}->{$cap} if $args->{desiredCapabilities}->{browserName} eq 'chrome';
             #Does not appear there are any MSIE based options, so let's just let that be
         }
         if (exists($args->{desiredCapabilities}->{browserName}) && $args->{desiredCapabilities}->{browserName} eq 'firefox' && $cap eq 'firefox_profile') {
@@ -904,6 +927,7 @@ sub _request_new_session {
         }
         delete $args->{capabilities}->{alwaysMatch}->{$cap} if !any { $_ eq $cap } @$caps;
     }
+    delete $args->{desiredCapabilities} if $FORCE_WD3; #XXX fork working-around busted fallback in firefox
     delete $args->{capabilities} if $FORCE_WD2; #XXX 'secret' feature to help the legacy unit tests to work
 
     # geckodriver has not yet implemented the GET /status endpoint

+ 1 - 1
lib/Selenium/Remote/WebElement.pm

@@ -393,7 +393,7 @@ sub get_element_location_in_view {
             return {y:pos.top,x:pos.left};
         }
         return {};
-    }, {'element-6066-11e4-a52e-4f735466cecf'=> $self->{id}} ) if $self->driver->{is_wd3} && grep { $self->driver->browser_name eq $_ } ('firefox','internet explorer', 'chrome');
+    }, {'element-6066-11e4-a52e-4f735466cecf'=> $self->{id}} ) if $self->driver->{is_wd3} && grep { $self->driver->browser_name eq $_ } ('firefox','internet explorer');
     my $res = { 'command' => 'getElementLocationInView', 'id' => $self->id };
     return $self->_execute_command($res);
 }

+ 2 - 2
t/01-webdriver3.t

@@ -93,9 +93,9 @@ NEWSESS: {
     is($self->{capabilities},'eee',"Caps set correctly in wd3 mode");
     is_deeply($args_modified->{capabilities},$expected,"Desired capabilities correctly translated to Firefox (WD3)");
 
-    $expected->{alwaysMatch}->{'chromeOptions'} = $expected->{alwaysMatch}->{'moz:firefoxOptions'};
+    #$expected->{alwaysMatch}->{'chromeOptions'} = $expected->{alwaysMatch}->{'moz:firefoxOptions'};
     $expected->{alwaysMatch}->{'moz:firefoxOptions'} = {};
-    $expected->{alwaysMatch}->{chromeOptions}->{args} = ['-profile', '~/.mozilla/firefox/vbdgri9o.default'];
+    #$expected->{alwaysMatch}->{chromeOptions}->{args} = ['-profile', '~/.mozilla/firefox/vbdgri9o.default'];
     $expected->{alwaysMatch}->{browserName} = 'chrome';
 
     $args->{desiredCapabilities}->{browserName} = 'chrome';