Parcourir la source

Fix #353: add child() and children() aliases to WebElement

George S. Baugh il y a 7 ans
Parent
commit
516aab5f94
3 fichiers modifiés avec 19 ajouts et 0 suppressions
  1. 1 0
      Changes
  2. 2 0
      at/sanity.test
  3. 16 0
      lib/Selenium/Remote/WebElement.pm

+ 1 - 0
Changes

@@ -4,6 +4,7 @@ Revision history for Selenium-Remote-Driver
         [New Features]
         - Selenium::Edge and Test::Selenium::Edge now exist
         - Pass caller argument array as final arg to error_handler callbacks
+        - Add child() and children() aliases to Selenium::Remote::WebElements
         [BUG FIXES]
         - Fixed Test::Selenium::* direct usage modules from getting undef method errors when acting on WebElements
         - Fixed issue where capabilities could not be passed with Selenium::Firefox

+ 2 - 0
at/sanity.test

@@ -98,12 +98,14 @@ is(scalar(@{$driver->find_elements('red','class')}),2,"can find multiple element
 
 my $lem = $driver->find_element('body', 'tag_name');
 isa_ok($driver->find_child_element($lem, 'red','class'),"Selenium::Remote::WebElement");
+isa_ok($lem->child('red','class'),"Selenium::Remote::WebElement");
 isa_ok($driver->find_child_element($lem, 'text','name'),"Selenium::Remote::WebElement");
 isa_ok($driver->find_child_element($lem, 'Test Link', 'link_text'),"Selenium::Remote::WebElement");
 isa_ok($driver->find_child_element($lem, 'Test', 'partial_link_text'),"Selenium::Remote::WebElement");
 
 $lem = $driver->find_element('form','tag_name');
 is(scalar(@{$driver->find_child_elements($lem,'./*')}),6,"can find child elements (WD3)");
+is(scalar(@{$lem->children('./*')}),6,"can find child elements via children() alias (WD3)");
 
 isa_ok($driver->get_active_element(),"Selenium::Remote::WebElement");
 

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

@@ -111,6 +111,22 @@ has 'driver' => (
 
 =head1 FUNCTIONS
 
+=head2 child(selector, method)
+
+=head2 children(selector, method)
+
+Alias to Selenium::Remote::Driver::find_child_element and find_child_elements, respectively.
+
+=cut
+
+sub child {
+    return $_[0]->{driver}->find_child_element(@_);
+}
+
+sub children {
+    return $_[0]->{driver}->find_child_elements(@_);
+}
+
 =head2 click
 
  Description: