Explorar el Código

Impleted all the WebElement related commands. Still need to document all these methods.

Aditya Ivaturi hace 15 años
padre
commit
f98b8cc991
Se han modificado 3 ficheros con 215 adiciones y 44 borrados
  1. 12 15
      lib/Selenium/Remote/Commands.pm
  2. 67 29
      lib/Selenium/Remote/Driver.pm
  3. 136 0
      lib/Selenium/Remote/WebElement.pm

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

@@ -195,27 +195,24 @@ sub new {
         },
         'getElementText' => {
                 'method' => 'GET',
-                'url' =>
-                  "session/:sessionId/element/:id/text"
+                'url' => "session/:sessionId/element/:id/text"
         },
         'getElementValueOfCssProperty' => {
             'method' => 'GET',
-            'url' =>
-"session/:sessionId/element/:id/css/:propertyName"
-        },
-        'getVisible' => {
-                       'method' => 'GET',
-                       'url' => "session/:sessionId/visible"
+            'url' => "session/:sessionId/element/:id/css/:propertyName"
         },
         'hoverOverElement' => {
                'method' => 'POST',
-               'url' =>
-                 "session/:sessionId/element/:id/hover"
-        },
-        'setVisible' => {
-                       'method' => 'POST',
-                       'url' => "session/:sessionId/visible"
-        },
+               'url' => "session/:sessionId/element/:id/hover"
+        },
+        #'setVisible' => {
+        #               'method' => 'POST',
+        #               'url' => "session/:sessionId/visible"
+        #},
+        #'getVisible' => {
+        #               'method' => 'GET',
+        #               'url' => "session/:sessionId/visible"
+        #},
     };
 
     bless $self, $class or die "Can't bless $class: $!";

+ 67 - 29
lib/Selenium/Remote/Driver.pm

@@ -602,6 +602,66 @@ sub find_elements {
     return $ret;
 }
 
+sub find_child_element {
+    my ( $self, $elem, $query, $method ) = @_;
+    my $ret;
+    if ( ( not defined $elem ) || ( not defined $query ) ) {
+        return "Missing parameters";
+    }
+    my $using = ( defined $method ) ? $method : 'xpath';
+    if (exists FINDERS->{$using}) {
+        my $res = { 'command' => 'findChildElement', 'id' => $elem->{id} };
+        my $params = { 'using' => $using, 'value' => $query };
+        my $ret_data = $self->_execute_command( $res, $params );
+        if (defined $ret_data->{'cmd_error'}) {
+            $ret = $ret_data;
+        }
+        else {
+            $ret_data->{'cmd_return'} = new Selenium::Remote::WebElement($ret_data->{'cmd_return'}->{ELEMENT}, $self);
+            $ret = $ret_data;
+        }
+    }
+    else {
+        $ret = "Bad method, expected - class, class_name, css, id, link,
+                link_text, partial_link_text, name, tag_name, xpath";
+    }
+    return $ret;
+}
+
+sub find_child_elements {
+    my ( $self, $elem, $query, $method ) = @_;
+    my $ret;
+    if ( ( not defined $elem ) || ( not defined $query ) ) {
+        return "Missing parameters";
+    }
+    my $using = ( defined $method ) ? $method : 'xpath';
+    if (exists FINDERS->{$using}) {
+        my $res = { 'command' => 'findChildElements', 'id' => $elem->{id} };
+        my $params = { 'using' => $using, 'value' => $query };
+        my $ret_data = $self->_execute_command( $res, $params );
+        if (defined $ret_data->{'cmd_error'}) {
+            $ret = $ret_data;
+        }
+        else {
+            my $elem_obj_arr;
+            my $i = 0;
+            my $elem_arr = $ret_data->{'cmd_return'};
+            foreach (@$elem_arr) {
+                $elem_obj_arr->[$i] = new Selenium::Remote::WebElement($_->{ELEMENT}, $self);
+                $i++;
+            }
+            $ret_data->{'cmd_return'} = $elem_obj_arr;
+            $ret = $ret_data;
+        }
+    }
+    else {
+        $ret = "Bad method, expected - class, class_name, css, id, link,
+                link_text, partial_link_text, name, tag_name, xpath";
+    }
+
+    return $ret;
+}
+
 sub get_active_element {
     my ($self) = @_;
     my $res = { 'command' => 'getActiveElement' };
@@ -619,38 +679,16 @@ sub describe_element {
     return "Not yet supported";
 }
 
-sub find_child_element {
-
-    # TODO: same as find_element - no idea what locator strategy string is & no
-    # idea what the id is.
-
-    my ( $self, $id, $query, $method ) = @_;
-    if ( ( not defined $id ) || ( not defined $query ) ) {
-        return "Missing parameters";
-    }
-    my $using = ( defined $method ) ? $method : 'xpath';
-    my $res = { 'command' => 'findChildElement', 'id' => $id };
-    my $params = { 'using' => $using, 'value' => $query };
-    return $self->_execute_command( $res, $params );
-}
-
-sub find_child_elements {
-
-    # TODO: same as find_element - no idea what locator strategy string is & no
-    # idea what the id is.
-
-    my ( $self, $id, $query, $method ) = @_;
-    if ( ( not defined $id ) || ( not defined $query ) ) {
-        return "Missing parameters";
-    }
-    my $using = ( defined $method ) ? $method : 'xpath';
-    my $res = { 'command' => 'findChildElements', 'id' => $id };
-    my $params = { 'using' => $using, 'value' => $query };
-    return $self->_execute_command( $res, $params );
+sub compare_elements {
+    my ($self, $elem1, $elem2) = @_;
+    my $res = { 'command' => 'elementEquals',
+                'id' => $elem1->{id},
+                'other' => $elem2->{id}
+              };
+    return $self->_execute_command($res);
 }
 
 
-
 1;
 
 __END__

+ 136 - 0
lib/Selenium/Remote/WebElement.pm

@@ -45,8 +45,144 @@ sub send_keys {
     return $driver->_execute_command($res, $params);
 }
 
+sub is_selected {
+    my ($self) = @_;
+    my $res = { 'command' => 'isElementSelected', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub set_selected {
+    my ($self) = @_;
+    my $res = { 'command' => 'setElementSelected', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub toggle {
+    my ($self) = @_;
+    my $res = { 'command' => 'toggleElement', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub is_enabled {
+    my ($self) = @_;
+    my $res = { 'command' => 'isElementEnabled', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub get_element_location {
+    my ($self) = @_;
+    my $res = { 'command' => 'getElementLocation', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
 
+sub get_element_location_in_view {
+    my ($self) = @_;
+    my $res = { 'command' => 'getElementLocationInView', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
 
+sub get_tag_name {
+    my ($self) = @_;
+    my $res = { 'command' => 'getElementTagName', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub clear {
+    my ($self) = @_;
+    my $res = { 'command' => 'clearElement', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub get_attribute {
+    my ($self, $attr_name) = @_;
+    if (not defined $attr_name) {
+        return 'Attribute name not provided';
+    }
+    my $res = {'command' => 'getElementAttribute',
+               'id' => $self->{id},
+               'name' => $attr_name,
+               };
+    return $driver->_execute_command($res);
+}
+
+sub is_displayed {
+    my ($self) = @_;
+    my $res = { 'command' => 'isElementDisplayed', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub drag {
+    my ($self, $x, $y) = @_;
+    if ((not defined $x) || (not defined $y)){
+        return 'X & Y pixel coordinates not provided';
+    }
+    my $res = {'command' => 'dragElement','id' => $self->{id}};
+    my $params = {
+        'x' => $x,
+        'y' => $y,
+    };
+    return $driver->_execute_command($res, $params);
+}
+
+sub get_size {
+    my ($self) = @_;
+    my $res = { 'command' => 'getElementSize', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub get_text {
+    my ($self) = @_;
+    my $res = { 'command' => 'getElementText', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
+
+sub get_css_attribute {
+    my ($self, $attr_name) = @_;
+    if (not defined $attr_name) {
+        return 'CSS attribute name not provided';
+    }
+    my $res = {'command' => 'getElementValueOfCssProperty',
+               'id' => $self->{id},
+               'property_name' => $attr_name,
+               };
+    return $driver->_execute_command($res);
+}
+
+sub hover {
+    my ($self) = @_;
+    my $res = { 'command' => 'hoverOverElement', 'id' => $self->{id} };
+    return $driver->_execute_command($res);
+}
 
 
 1;
+
+=head1 SEE ALSO
+
+For more information about Selenium , visit the website at
+L<http://code.google.com/p/selenium/>.
+
+=head1 BUGS
+
+The Selenium issue tracking system is available online at
+L<http://code.google.com/p/selenium/issues/list>.
+
+=head1 AUTHOR
+
+Perl Bindings for Remote Driver by Aditya Ivaturi <ivaturi@gmail.com>
+
+=head1 LICENSE
+
+Copyright (c) 2010 Aditya Ivaturi
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.