Pārlūkot izejas kodu

Start work on supporting Selenium 4

For now just gather whether the server "looks like 4" and store
this data.
Andy Baugh 2 gadi atpakaļ
vecāks
revīzija
0dbbdbf437

+ 4 - 3
lib/Selenium/Remote/Driver.pm

@@ -49,6 +49,7 @@ use constant FINDERS => {
 
 our $FORCE_WD2            = 0;
 our $FORCE_WD3            = 0;
+our $FORCE_WD4            = 0;
 our %CURRENT_ACTION_CHAIN = ( actions => [] );
 
 =for Pod::Coverage BUILD
@@ -1062,8 +1063,9 @@ sub _request_new_session {
         }
     }
 
-    # Get actual status
-    $self->remote_conn->check_status();
+    # Die unless connection is good
+    my $rc = $self->remote_conn;
+    $rc->check_status();
 
     # command => 'newSession' to fool the tests of commands implemented
     # TODO: rewrite the testing better, this is so fragile.
@@ -1073,7 +1075,6 @@ sub _request_new_session {
         no_content_success =>
           $self->commands->get_no_content_success('newSession'),
     };
-    my $rc = $self->remote_conn;
     my $resp = $rc->request( $resource_new_session, $args, );
 
     if ( $resp->{cmd_status} && $resp->{cmd_status} eq 'NOT OK' ) {

+ 31 - 4
lib/Selenium/Remote/RemoteConnection.pm

@@ -12,17 +12,22 @@ use HTTP::Headers;
 use HTTP::Request;
 use Carp qw(croak);
 use JSON;
-use Data::Dumper;
 use Selenium::Remote::ErrorHandler;
 use Scalar::Util qw{looks_like_number};
 
-has 'remote_server_addr' => ( is => 'rw', );
+has 'remote_server_addr' => (
+    is      => 'rw', 
+    default => '127.0.0.1',
+);
 
-has 'port' => ( is => 'rw', );
+has 'port' => (
+    is        => 'rw', 
+    'default' => 4444,
+);
 
 has 'debug' => (
     is      => 'rw',
-    default => sub { 0 }
+    default => 0, 
 );
 
 has 'ua' => (
@@ -100,6 +105,27 @@ sub check_status {
     unless ( $cmdOut eq 'OK' ) {
         croak "Selenium server did not return proper status";
     }
+
+    # While we're here, let's try to find out what server version we're on.
+    my $response = $status->{'cmd_out'};
+    if( ref $response eq 'HASH' ) {
+        # Selenium 4 pathway
+        my $curr_component = $response;
+        my $looks_like_4;
+        foreach my $key (qw{value nodes 0 version}) {
+            if( $key eq '0' ) { # We must at least have one node in the grid.
+                last if !$curr_component->[0];
+            } else {
+                last if !$curr_component->{$key};
+            }
+            $looks_like_4 = $response->{'value'}{'nodes'}[0]{'version'};
+        }
+        if($looks_like_4) {
+            $self->{'version'} = 4;
+            $self->{'version_full'} = $looks_like_4;
+        }
+    }
+    return;
 }
 
 =head2 request
@@ -216,6 +242,7 @@ sub _process_response {
         elsif ( $response->is_success ) {
             $data->{'cmd_status'} = 'OK';
             if ( defined $decoded_json ) {
+                $data->{'cmd_out'} = $decoded_json;
 
                 #XXX MS edge doesn't follow spec here either
                 if (   looks_like_number( $decoded_json->{status} )