Browse Source

getting places

Andy Baugh 2 năm trước cách đây
mục cha
commit
85e797983c
3 tập tin đã thay đổi với 13 bổ sung10 xóa
  1. 4 2
      at/sanity-v4.test
  2. 1 1
      lib/Selenium/Remote/Driver.pm
  3. 8 7
      lib/Selenium/Remote/Driver/v4.pm

+ 4 - 2
at/sanity-v4.test

@@ -24,14 +24,16 @@ my $driver = Selenium::Remote::Driver->new(
     extra_capabilities => {
         log => { level => 'trace' },
     },
+    'force_version' => 4,
+    'debug' => 1,
 );
 isa_ok($driver,'Selenium::Remote::Driver::v4',"Can get new S::R::D::v4") or die diag explain $driver;
 
 $driver->debug_on();
 
-is($driver->get_capabilities()->{browserName},'firefox',"Can get Capabilities correctly (WD3)");
+like( exception { $driver->get_capabilities() },qr/unimplemented/i,"Can't get Capabilities correctly (WD4)");
 my $sessions = $driver->get_sessions();
-is(scalar(@$sessions),1,"Can fall back to selenium2 to list sessions");
+is(scalar(@$sessions),1,"Can list sessions");
 
 ok($driver->status()->{ready},"status reports OK (WD3)");
 

+ 1 - 1
lib/Selenium/Remote/Driver.pm

@@ -509,7 +509,7 @@ sub new {
 		port               => $opts{port},
 	);
 	$conn->check_status();
-	if( $conn->{'version'} && $conn->{'version'} == 4 ) {
+	if( $opts{'force_version'} eq '4' || ( $conn->{'version'} && $conn->{'version'} == 4 ) ) {
 		require Selenium::Remote::Driver::v4;
 		return Selenium::Remote::Driver::v4->new(
 			'port'    => $opts{port},

+ 8 - 7
lib/Selenium/Remote/Driver/v4.pm

@@ -16,6 +16,10 @@ sub new {
     $self->{'debug'} = $opts{'debug'};
     
     $self->_install_wrapper_subs();
+    
+    # Create the session, as users expect this
+    $self->{'_client'}->NewSession();
+
     return $self;
 }
 
@@ -94,12 +98,9 @@ my @unimplemented = qw{
 
 sub _install_wrapper_subs {
     my ( $self ) = @_;
-    foreach my $sub_per_spec (keys(%{$self->{client}{spec}})) {
+    foreach my $sub_per_spec (keys(%{$self->{_client}{spec}})) {
         my $sub2install = $cmd_map{$sub_per_spec};
-        if( !$sub2install ) {
-            print "Can't install a subroutine to match '$sub_per_spec', as it isn't mapped to the S::R::D equivalent!" if $self->{'debug'};
-            next;
-        }
+        next if( !$sub2install );
 
         # Yo dawg... I herd u like Sub::Install
         Sub::Install::install_sub(
@@ -132,7 +133,7 @@ sub is_webdriver_3 { return 0 }
 sub has_javascript { return 1 }
 sub debug_on { return $_[0]->{'debug'} = 1 }
 sub debug_off { return $_[0]->{'debug'} = 0 }
-sub get_sessions { return $_[0]->{'client'}{'sessions'} }
+sub get_sessions { return $_[0]->{'_client'}{'sessions'} }
 
 sub send_keys_to_active_element {
     my ($self, $keys) = @_;
@@ -142,7 +143,7 @@ sub send_keys_to_active_element {
 
 sub quit {
     my ($self) = @_;
-    undef $self->{'client'};
+    undef $self->{'_client'};
     return undef $self;
 }
 *DESTROY = \&quit;