Skip to content

Commit

Permalink
Fix edge case with driver spawns
Browse files Browse the repository at this point in the history
  • Loading branch information
teodesian committed Apr 12, 2021
1 parent 30eb103 commit e6bed62
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Revision history for Selenium-Client

1.03 2021-04-12 TEODESIAN
[BUG FIXES]
- Don't clobber $? in destructor
- Use Playwright.pm's more clever DESTROY code

1.02 2021-02-10 TEODESIAN
[BUG FIXES]
- Declare minimum version of perl 5.28
Expand Down
6 changes: 3 additions & 3 deletions at/sanity.test
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ foreach my $browser (@browsers) {
is($session->GetPageSource(),"<html><head></head><body>ZIPPY\n</body></html>","Can get page source");
is(exception { $session->Back() }, undef, "Can navigate to the last page visited with back()");

alertify($session) unless $browser eq 'safari';
alertify($session) unless $browser eq 'safari' || $browser eq 'firefox';
is(exception { $session->Forward() }, undef, "Can navigate back to previously visited page with forward()");

$session->Back();
Expand Down Expand Up @@ -145,8 +145,8 @@ foreach my $browser (@browsers) {
is($rekt, \%erekt, "Can get window rect");
}
#Frames
my $frame = $session->FindElement( using => 'css selector', value => '#frame' );
is( exception { $session->SwitchToFrame( id => $frame->{elementid} ) }, undef, "Can switch into frame");
#my $frame = $session->FindElement( using => 'css selector', value => '#frame' );
#is( exception { $session->SwitchToFrame( id => $frame->{elementid} ) }, undef, "Can switch into frame");
#XXX the above actually does not do anything, only switching by window.frames index actually works lol
$session->SwitchToFrame( id => 0 );
# Check that the driver yanno *actually did something*
Expand Down
2 changes: 1 addition & 1 deletion dist.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = Selenium-Client
version = 1.02
version = 1.03
author = George S. Baugh <george@troglodyne.net>
license = MIT
copyright_holder = George S. Baugh
Expand Down
20 changes: 19 additions & 1 deletion lib/Selenium/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,25 @@ sub DESTROY($self) {
kill $sig, $self->{pid};

print "Issued SIG$sig to $self->{pid}, waiting...\n" if $self->{debug};
return waitpid( $self->{pid}, 0 );

# 0 is always WCONTINUED, 1 is always WNOHANG, and POSIX is an expensive import
# When 0 is returned, the process is still active, so it needs more persuasion
foreach (0..3) {
return unless waitpid( $self->{pid}, 1) == 0;
sleep 1;
}

# Advanced persuasion
print "Forcibly terminating selenium server process...\n" if $self->{debug};
kill('TERM', $self->{pid});

#XXX unfortunately I can't just do a SIGALRM, because blocking system calls can't be intercepted on win32
foreach (0..$self->{timeout}) {
return unless waitpid( $self->{pid}, 1 ) == 0;
sleep 1;
}
warn "Could not shut down selenium server!";
return;
}

sub _is_windows {
Expand Down

0 comments on commit e6bed62

Please sign in to comment.