浏览代码

Use $self->FINDERS to allow for modification in inherited classes

Appium has a different list of FINDERS strategies than
Webdriver. Although we can read the FINDERS constant from inherited
classes, I do not believe we can change it from there without having to
overwrite the subroutine in S::R::D's Driver.pm, as the `find_element*`
functions were hardwired to use their FINDERS constant only. Now, they
look for the FINDERS sub on $self, and we can provide a different
FINDERS in inherited classes.
Daniel Gempesaw 11 年之前
父节点
当前提交
ea68e064fc
共有 1 个文件被更改,包括 7 次插入7 次删除
  1. 7 7
      lib/Selenium/Remote/Driver.pm

+ 7 - 7
lib/Selenium/Remote/Driver.pm

@@ -300,7 +300,7 @@ has 'webelement_class' => (
 
 has 'default_finder' => (
     is      => 'rw',
-    coerce  => sub { FINDERS->{ $_[0] } },
+    coerce  => sub { __PACKAGE__->FINDERS->{ $_[0] } },
     default => sub {'xpath'},
 );
 
@@ -1753,7 +1753,7 @@ sub find_element {
         croak 'Search string to find element not provided.';
     }
     my $using =
-      ( defined $method ) ? FINDERS->{$method} : $self->default_finder;
+      ( defined $method ) ? $self->FINDERS->{$method} : $self->default_finder;
     if ( defined $using ) {
         my $res = { 'command' => 'findElement' };
         my $params = { 'using' => $using, 'value' => $query };
@@ -1812,7 +1812,7 @@ sub find_elements {
     }
 
     my $using =
-      ( defined $method ) ? FINDERS->{$method} : $self->default_finder;
+      ( defined $method ) ? $self->FINDERS->{$method} : $self->default_finder;
 
     if ( defined $using ) {
         my $res = { 'command' => 'findElements' };
@@ -1887,9 +1887,9 @@ sub find_child_element {
         croak "Missing parameters";
     }
     my $using = ( defined $method ) ? $method : $self->default_finder;
-    if ( exists FINDERS->{$using} ) {
+    if ( exists $self->FINDERS->{$using} ) {
         my $res = { 'command' => 'findChildElement', 'id' => $elem->{id} };
-        my $params = { 'using' => FINDERS->{$using}, 'value' => $query };
+        my $params = { 'using' => $self->FINDERS->{$using}, 'value' => $query };
         my $ret_data = eval { $self->_execute_command( $res, $params ); };
         if ($@) {
             if ( $@
@@ -1948,9 +1948,9 @@ sub find_child_elements {
         croak "Missing parameters";
     }
     my $using = ( defined $method ) ? $method : $self->default_finder;
-    if ( exists FINDERS->{$using} ) {
+    if ( exists $self->FINDERS->{$using} ) {
         my $res = { 'command' => 'findChildElements', 'id' => $elem->{id} };
-        my $params = { 'using' => FINDERS->{$using}, 'value' => $query };
+        my $params = { 'using' => $self->FINDERS->{$using}, 'value' => $query };
         my $ret_data = eval { $self->_execute_command( $res, $params ); };
         if ($@) {
             if ( $@