Ver código fonte

Add a predicate to restrict has_base_url

This preserves the previous behavior of ->get() failing on an invalid
url. The base_url property should only kick in if it's specified during
construction to prevent action at a distance for users who aren't aware
of the attribute.
Daniel Gempesaw 11 anos atrás
pai
commit
dde2e9dae4
1 arquivos alterados com 6 adições e 5 exclusões
  1. 6 5
      lib/Selenium/Remote/Driver.pm

+ 6 - 5
lib/Selenium/Remote/Driver.pm

@@ -146,7 +146,7 @@ available here.
         'default_finder'       - <string>   - choose default finder used for find_element* {class|class_name|css|id|link|link_text|name|partial_link_text|tag_name|xpath}
         'webelement_class'     - <string>   - sub-class of Selenium::Remote::WebElement if you wish to use an alternate WebElement class.
         'ua'                   - LWP::UserAgent instance - if you wish to use a specific $ua, like from Test::LWP::UserAgent
-        'base_url'             - <string>   - base url for the website Selenium acts on, default is 'http://localhost'
+        'base_url'             - <string>   - OPTIONAL, base url for the website Selenium acts on. This can save you from repeating the domain in every call to $driver->get()
 
 
     If no values are provided, then these defaults will be assumed:
@@ -266,12 +266,13 @@ has 'browser_name' => (
 
 has 'base_url' => (
     is      => 'rw',
-    coerce  => sub { 
-        my $base_url = shift || 'http://localhost';
+    lazy    => 1,
+    coerce  => sub {
+        my $base_url = shift;
         $base_url =~ s|/$||;
         return $base_url;
     },
-    default => sub {'http://localhost'},
+    predicate => 'has_base_url',
 );
 
 has 'platform' => (
@@ -1074,7 +1075,7 @@ sub navigate {
 sub get {
     my ( $self, $url ) = @_;
 
-    if ($url !~ m|://|) {
+    if ($self->has_base_url && $url !~ m|://|) {
         $url =~ s|^/||;
         $url = $self->base_url . "/" . $url;
     }