浏览代码

Implemented all the remaining commands.

Aditya Ivaturi 15 年之前
父节点
当前提交
516c3277b0
共有 1 个文件被更改,包括 32 次插入19 次删除
  1. 32 19
      lib/Selenium/Remote/Driver.pm

+ 32 - 19
lib/Selenium/Remote/Driver.pm

@@ -201,6 +201,13 @@ sub get_capabilities {
     return $self->_execute_command($res);
 }
 
+sub set_implicit_wait_timeout {
+    my ($self, $ms) = @_;
+    my $res  = {'command' => 'setImplicitWaitTimeout'};
+    my $params  = {'ms' => $ms};
+    return $self->_execute_command($res, $params);
+}
+
 =head2 quit
 
  Description:
@@ -380,23 +387,34 @@ sub refresh {
 }
 
 sub execute_script {
-
-    # TODO: this method is not finished
-
     my ( $self, $script, @args ) = @_;
-    if ( not defined $script ) {
-        return 'No script provided';
-    }
-    my $res  = { 'command'    => 'executeScript' };
-    my $args = { 'session_id' => $self->{'session_id'}, };
-    my $resource = $self->{commands}->getParams( $res, $args );
-
-    if ($resource) {
-        return $self->{remote_conn}
-          ->request( $resource->{'method'}, $resource->{'url'} );
+    if ($self->javascript) {
+        if ( not defined $script ) {
+            return 'No script provided';
+        }
+        my $res  = { 'command'    => 'executeScript' };
+        
+        # Check the args array if the elem obj is provided & replace it with
+        # JSON representation
+        for (my $i=0; $i<@args; $i++) {
+            if (ref $args[$i] eq 'Selenium::Remote::WebElement') {
+                $args[$i] = {'ELEMENT' => ($args[$i])->{id}};
+            }
+        }
+        
+        my $params = {'args' => @args};
+        my $ret = $self->_execute_command($res, $params);
+        
+        # replace any ELEMENTS with WebElement
+        if (exists $ret->{'cmd_return'}->{'ELEMENT'}) {
+            $ret->{'cmd_return'} =
+                new Selenium::Remote::WebElement(
+                                        $ret->{'cmd_return'}->{ELEMENT}, $self);
+        }
+        return $ret;
     }
     else {
-        croak "Couldn't retrieve command $res settings\n";
+        return 'Javascript is not enabled on remote driver instance.';
     }
 }
 
@@ -419,8 +437,6 @@ sub screenshot {
     return $self->_execute_command($res);
 }
 
-
-
 sub switch_to_frame {
     my ( $self, $id ) = @_;
     my $json_null = JSON::null;
@@ -484,9 +500,6 @@ sub set_speed {
     return $self->_execute_command( $res, $params );
 }
 
-# TODO: Verify all these cookied methods - some return errors some don't
-#       No idea whether they're implemented on the server yet
-
 sub get_all_cookies {
     my ($self) = @_;
     my $res = { 'command' => 'getAllCookies' };