Bladeren bron

Merge pull request #323 from gerhardj/master

Fix set_timeout and move_to for Selenium::Firefox
George S. Baugh 8 jaren geleden
bovenliggende
commit
d68caafce1
2 gewijzigde bestanden met toevoegingen van 46 en 1 verwijderingen
  1. 5 0
      lib/Selenium/Remote/Commands.pm
  2. 41 1
      lib/Selenium/Remote/Driver.pm

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

@@ -344,6 +344,11 @@ has '_cmds' => (
                 'url'                => 'session/:sessionId/buttonup',
                 'no_content_success' => 1
             },
+            'generalAction' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/actions',
+                'no_content_success' => 1
+            },
             'uploadFile' => {
                 'method'             => 'POST',
                 'url'                => 'session/:sessionId/file',

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

@@ -1008,6 +1008,46 @@ sub move_to {
     return shift->mouse_move_to_location(@_);
 }
 
+=head2 move_action
+
+ Description:
+    Move the mouse similarly to the mouse_move_to_location. But uses the
+    new webdriver actions API which is supported by geckodriver.
+
+ Output:
+    STRING -
+
+ Usage:
+    # element - the element to move to. Must be specified.
+    # xoffset - X offset to move to, relative to the center of the element. If not specified, the mouse will move to the middle of the element.
+    # yoffset - Y offset to move to, relative to the center of the element. If not specified, the mouse will move to the middle of the element.
+
+    print $driver->move_action(element => e, xoffset => x, yoffset => y);
+
+=cut
+
+sub move_action {
+    my ( $self, %args ) = @_;
+    my $params = {
+        actions => [{
+            type => "pointer",
+            id => 'my pointer move',
+            "parameters" => { "pointerType" => "mouse" },
+            actions => [
+                {
+                    type => "pointerMove",
+                    duration => 0,
+                    x => $args{xoffset} // 0,
+                    y => $args{yoffset} // 0,
+                    origin => {'element-6066-11e4-a52e-4f735466cecf' => $args{element}{id}},
+                },
+            ],
+        }],
+    };
+    my $res = { 'command' => 'generalAction' };
+    return $self->_execute_command( $res, $params );
+}
+
 =head2 get_capabilities
 
  Description:
@@ -1056,7 +1096,7 @@ sub set_timeout {
     $ms = _coerce_timeout_ms( $ms );
 
     my $res = { 'command' => 'setTimeout' };
-    my $params = { 'type' => $type, 'ms' => $ms };
+    my $params = { 'type' => $type, 'ms' => $ms, $type => $ms };
     return $self->_execute_command( $res, $params );
 }