Kaynağa Gözat

Refactor binary shutdown to fix convenience.t test

Daniel Gempesaw 10 yıl önce
ebeveyn
işleme
bff21b8c52

+ 14 - 3
lib/Selenium/BinaryModeBuilder.pm

@@ -10,10 +10,10 @@ use Try::Tiny;
 use Moo::Role;
 
 has 'binary_mode' => (
-    is => 'ro',
+    is => 'lazy',
     init_arg => undef,
-    lazy => 1,
-    builder => 1
+    builder => 1,
+    predicate => 1
 );
 
 has 'try_binary' => (
@@ -79,6 +79,17 @@ sub start_binary_on_port {
     }
 }
 
+sub shutdown_binary {
+    my ($self) = @_;
+
+    if ($self->has_binary_mode && $self->binary_mode) {
+        my $port = $self->port;
+        my $ua = $self->ua;
+
+        $ua->get('127.0.0.1:' . $port . '/wd/hub/shutdown');
+    }
+}
+
 sub _find_executable {
     my ($binary) = @_;
 

+ 1 - 6
lib/Selenium/Chrome.pm

@@ -54,12 +54,7 @@ has 'binary_port' => (
 sub DEMOLISH {
     my ($self) = @_;
 
-    if ($self->binary_mode) {
-        my $port = $self->port;
-        my $ua = $self->ua;
-
-        $ua->get('127.0.0.1:' . $port . '/wd/hub/shutdown');
-    }
+    $self->shutdown_binary;
 }
 
 1;

+ 1 - 6
lib/Selenium/PhantomJS.pm

@@ -55,12 +55,7 @@ has 'binary_port' => (
 sub DEMOLISH {
     my ($self) = @_;
 
-    if ($self->binary_mode) {
-        my $port = $self->port;
-        my $ua = $self->ua;
-
-        $ua->get('127.0.0.1:' . $port . '/wd/hub/shutdown');
-    }
+    $self->shutdown_binary;
 }
 
 1;