Forráskód Böngészése

Added two new helper methods: debug_on & debug_off. debug_on will turn on dumping of content sent back & forth with webdriver. Useful in debugging.

Aditya Ivaturi 13 éve
szülő
commit
b94424884d
2 módosított fájl, 38 hozzáadás és 1 törlés
  1. 32 0
      lib/Selenium/Remote/Driver.pm
  2. 6 1
      lib/Selenium/Remote/RemoteConnection.pm

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

@@ -300,6 +300,38 @@ sub new_session {
     }
 }
 
+=head2 debug_on
+
+  Description:
+    Turns on debugging mode and the driver will print extra info like request
+    and response to stdout. Useful, when you want to see what is being sent to
+    the server & what response you are getting back.
+
+  Usage:
+    $driver->debug_on;
+
+=cut
+
+sub debug_on {
+    my ($self) = @_;
+    $self->{'remote_conn'}->{'debug'} = 1;
+}
+
+=head2 debug_off
+
+  Description:
+    Turns off the debugging mode.
+
+  Usage:
+    $driver->debug_off;
+
+=cut
+
+sub debug_off {
+    my ($self) = @_;
+    $self->{'remote_conn'}->{'debug'} = 0;
+}
+
 =head2 get_sessions
 
   Description:

+ 6 - 1
lib/Selenium/Remote/RemoteConnection.pm

@@ -19,6 +19,7 @@ sub new {
     my $self = {
                  remote_server_addr => $remote_srvr,
                  port               => $port,
+                 debug              => 0,
     };
     bless $self, $class or die "Can't bless $class: $!";
     my $status = eval {$self->request('GET','status');};
@@ -62,8 +63,11 @@ sub request {
 
     if ((defined $params) && $params ne '') {
         my $json = new JSON;
+        $json->allow_blessed;
         $content = $json->allow_nonref->utf8->encode($params);
     }
+    
+    print "REQ: $url, $content\n" if $self->{debug};
 
     # HTTP request
     my $ua = LWP::UserAgent->new;
@@ -85,7 +89,8 @@ sub _process_response {
         return $self->request('GET', $response->header('location'));
     }
     else {
-        my $decoded_json = undef; 
+        my $decoded_json = undef;
+        print "RES: ".$response->decoded_content."\n\n" if $self->{debug};
         if (($response->message ne 'No Content') && ($response->content ne '')) {
             $decoded_json = $json->allow_nonref(1)->utf8(1)->decode($response->content);
             $data->{'sessionId'} = $decoded_json->{'sessionId'};