Prechádzať zdrojové kódy

Added auto close in DESTROY method

Aditya Ivaturi 15 rokov pred
rodič
commit
67cb78346e
1 zmenil súbory, kde vykonal 8 pridanie a 1 odobranie
  1. 8 1
      lib/Selenium/Remote/Driver.pm

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

@@ -114,6 +114,7 @@ sub new {
         session_id         => undef,
         remote_conn        => undef,
         commands           => $ress,
+        auto_close         => 1, # by default we will close remote session on DESTROY
     };
     bless $self, $class or die "Can't bless $class: $!";
 
@@ -142,6 +143,11 @@ sub new {
     return $self;
 }
 
+sub DESTROY {
+    my ($self) = @_;
+    $self->quit() if ($self->{auto_close} && defined $self->{session_id});
+}
+
 # This is an internal method used the Driver & is not supposed to be used by
 # end user. This method is used by Driver to set up all the parameters (url & JSON),
 # send commands & receive response from the server.
@@ -223,7 +229,8 @@ sub set_implicit_wait_timeout {
 sub quit {
     my $self = shift;
     my $res = { 'command' => 'quit' };
-    return $self->_execute_command($res);
+    $self->_execute_command($res);
+    $self->{session_id} = undef;
 }
 
 =head2 get_current_window_handle