浏览代码

Handle geckodriver's execute_script endpoints

Daniel Gempesaw 8 年之前
父节点
当前提交
a462d84da2
共有 4 个文件被更改,包括 32 次插入3 次删除
  1. 5 0
      lib/Selenium/Firefox.pm
  2. 12 0
      lib/Selenium/Remote/Commands.pm
  3. 14 2
      lib/Selenium/Remote/Driver.pm
  4. 1 1
      t/04-commands-implemented.t

+ 5 - 0
lib/Selenium/Firefox.pm

@@ -245,6 +245,11 @@ has 'firefox_binary' => (
     builder => 'firefox_path'
 );
 
+has '_execute_script_suffix' => (
+    is => 'lazy',
+    default => 'Gecko'
+);
+
 =head2 get_context
 
  Description:

+ 12 - 0
lib/Selenium/Remote/Commands.pm

@@ -406,6 +406,18 @@ has '_cmds' => (
                 'no_content_success' => 0
             },
 
+            # geckodriver workarounds
+            'executeScriptGecko' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/execute/sync',
+                'no_content_success' => 0
+            },
+            'executeAsyncScriptGecko' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/execute/async',
+                'no_content_success' => 0
+            },
+
             # /session/:sessionId/local_storage
             # /session/:sessionId/local_storage/key/:key
             # /session/:sessionId/local_storage/size

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

@@ -563,6 +563,18 @@ has 'inner_window_size' => (
 
 );
 
+# At the time of writing, Geckodriver uses a different endpoint than
+# the java bindings for executing synchronous and asynchronous
+# scripts. As a matter of fact, Geckodriver does conform to the W3C
+# spec, but as are bound to support both while the java bindings
+# transition to full spec support, we need some way to handle the
+# difference.
+
+has '_execute_script_suffix' => (
+    is => 'lazy',
+    default => ''
+);
+
 with 'Selenium::Remote::Finders';
 with 'Selenium::Remote::Driver::CanSetWebdriverContext';
 
@@ -1449,7 +1461,7 @@ sub execute_async_script {
         if ( not defined $script ) {
             croak 'No script provided';
         }
-        my $res = { 'command' => 'executeAsyncScript' };
+        my $res = { 'command' => 'executeAsyncScript' . $self->_execute_script_suffix};
 
         # Check the args array if the elem obj is provided & replace it with
         # JSON representation
@@ -1515,7 +1527,7 @@ sub execute_script {
         if ( not defined $script ) {
             croak 'No script provided';
         }
-        my $res = { 'command' => 'executeScript' };
+        my $res = { 'command' => 'executeScript' . $self->_execute_script_suffix };
 
         # Check the args array if the elem obj is provided & replace it with
         # JSON representation

+ 1 - 1
t/04-commands-implemented.t

@@ -26,7 +26,7 @@ for my $command (keys %{$comm}) {
       }
     }
   }
-  if (!$found_command) {
+  if (!$found_command && $command !~ /Gecko/) {
     fail("find $command");
   }
 }