Răsfoiți Sursa

Fix #54: update status endpoint when checking for Grid hub

Daniel Gempesaw 11 ani în urmă
părinte
comite
597508233d
2 a modificat fișierele cu 33 adăugiri și 2 ștergeri
  1. 5 2
      lib/Selenium/Remote/RemoteConnection.pm
  2. 28 0
      t/01-driver.t

+ 5 - 2
lib/Selenium/Remote/RemoteConnection.pm

@@ -35,16 +35,18 @@ sub BUILD {
     my $self = shift;
     my $status;
     try {
-      $status = $self->request('GET','status');
+        $status = $self->request('GET','status');
     }
     catch {
         croak "Could not connect to SeleniumWebDriver: $_" ;
     };
+
     if($status->{cmd_status} ne 'OK') {
         # Could be grid, see if we can talk to it
         $status = undef;
-        $status = $self->request('GET', 'grid/api/testsession');
+        $status = $self->request('GET', 'grid/api/hub/status');
     }
+
     unless ($status->{cmd_status} eq 'OK') {
         croak "Selenium server did not return proper status";
     }
@@ -105,6 +107,7 @@ sub _process_response {
     else {
         my $decoded_json = undef;
         print "RES: ".$response->decoded_content."\n\n" if $self->debug;
+
         if (($response->message ne 'No Content') && ($response->content ne '')) {
             if ($response->content_type !~ m/json/i) {
                 $data->{'cmd_return'} = 'Server returned error message '.$response->content.' instead of data';

+ 28 - 0
t/01-driver.t

@@ -112,6 +112,34 @@ DESIRED_CAPABILITIES: {
     ok($requests_count == 3, 'The new_from_caps section has the correct number of requests to /session/');
 }
 
+GRID_STARTUP: {
+    # Mimicking a grid server; /wd/hub/status fails, and we expect
+    # grid/api/hub/status to be checked instead.
+    my $tua = Test::LWP::UserAgent->new;
+    my $not_ok = sub {
+        return HTTP::Response->new(500, 'NOTOK');
+    };
+    $tua->map_response(qr{wd/hub/status}, $not_ok);
+
+    my $grid_status_count = 0;
+    my $ok = sub {
+        my $res = {
+            cmd_return => {},
+            cmd_status => 'OK',
+            sessionId => '123124123'
+        };
+        $grid_status_count++;
+        return HTTP::Response->new(200, 'OK', ['Content-Type' => 'application/json'], to_json($res));
+    };
+    $tua->map_response(qr{(?:grid/api/hub/status|session)}, $ok);
+
+    my $grid_driver = Selenium::Remote::Driver->new(ua => $tua);
+
+    ok(defined $grid_driver, 'Grid: Object loaded fine using grid/api/hub/status');
+    ok($grid_driver->isa('Selenium::Remote::Driver'), 'Grid: ...and of right type');
+    ok($grid_status_count == 2, 'checked Grid specific status');
+}
+
 CHECK_DRIVER: {
     ok(defined $driver, 'Object loaded fine...');
     ok($driver->isa('Selenium::Remote::Driver'), '...and of right type');