Bladeren bron

New shortcut methods have been absorbed from Test::WebDriver:

    get_body()
    get_text()
    get_path()
Mark Stosberg 12 jaren geleden
bovenliggende
commit
709fe75e95
2 gewijzigde bestanden met toevoegingen van 57 en 0 verwijderingen
  1. 6 0
      Changes
  2. 51 0
      lib/Selenium/Remote/Driver.pm

+ 6 - 0
Changes

@@ -20,6 +20,12 @@ Revision history for Selenium-Remote-Driver
         - new() now accepts a 'webelement_class' option to allow you to specify an alternate WebElement class.
           This could be used to add testing methods or functionality for WebElements.  
 
+        - New shortcut methods absorbed from Test::WebDriver:
+
+          get_text() Returns the text for a particular element.
+          get_body() Returns the text for the whole body.
+          get_path() Returns the path part of the current URL.
+
         [DOCUMENTATION]
         - Updated ChangeLog to reflect that debug_on() and debug_off() methods were added in 0.16.
 

+ 51 - 0
lib/Selenium/Remote/Driver.pm

@@ -1895,6 +1895,57 @@ sub upload_file {
     return $self->_execute_command($res, $params);
 }
 
+=head2 get_text
+
+ Description:
+    Get the text of a particular element. Wrapper around L<find_element()>
+
+ Usage:
+    $text = $driver->get_text("//div[\@name='q']");
+
+=cut
+
+sub get_text {
+    my $self = shift;
+    return $self->find_element(@_)->get_text();
+}
+
+=head2 get_body
+
+ Description:
+    Get the current text for the whole body. If you want the entire raw HTML instead,
+    See L<get_page_source>.
+
+ Usage:
+    $body_text = $driver->get_body();
+
+=cut
+
+sub get_body {
+    my $self = shift;
+    return $self->get_text('//body');
+}
+
+=head2 get_path
+
+ Description:
+     Get the path part of the current browser location.
+
+ Usage:
+     $path = $driver->get_path();
+
+=cut
+
+sub get_path {
+    my $self = shift;
+    my $location = $self->get_current_url;
+    $location =~ s/\?.*//; # strip of query params
+    $location =~ s/#.*//; # strip of anchors
+    $location =~ s#^https?://[^/]+##; # strip off host
+    return $location;
+}
+
+
 1;
 
 __END__