sub start_selenium_server {
my($self) = @_;
- if($self->{selenium_rc}{start}) {
- my $child = Child->new(sub {
- system('ssh', $self->{selenium_rc}{host}, 'vncserver',
- ":$self->{selenium_rc}{xvnc_display}");
- }
- );
- $self->{selenium_rc}{xvnc_server_proc} = $child->start;
- $child = Child->new(sub {
- system('ssh', $self->{selenium_rc}{host}, 'env',
- "DISPLAY=:$self->{selenium_rc}{xvnc_display}", 'selenium-rc', '-port',
- $self->{selenium_rc}{port} );
+ my $selrc = $self->{selenium_rc};
+ if($selrc->{start}) {
+ my ($host, $display, $port) = @{$selrc}{qw(host xvnc_display port)};
+ my @do_ssh = $host eq 'localhost' ? () : ('ssh', $host);
+ if ($selrc->{start_xvnc}) {
+ $selrc->{xvnc_server_proc} = Child->new(
+ sub {
+ exec(
+ @do_ssh,
+ 'vncserver', ":${display}",
+ );
+ }
+ )->start;
+ $selrc->{xvnc_started} = 1;
+ sleep 3;
+ }
+ $selrc->{selenium_server_proc} = Child->new(
+ sub {
+ exec(
+ @do_ssh,
+ 'env', "DISPLAY=:${display}", 'selenium-rc', '-port', $port
+ )
}
- );
- $self->{selenium_rc}{selenium_server_proc} = $child->start;
+ )->start;
+ sleep 1;
}
my $tries = 0;
while($tries < 5) {
sub stop_selenium_server {
my($self) = @_;
- # okay, we're done, kill the server.
- my $url = sprintf
- "http://%s:%s/selenium-server/driver/?cmd=shutDownSeleniumServer",
- $self->{selenium_rc}{host}, $self->{selenium_rc}{port};
- get($url);
- delete $self->{src};
- $self->{selenium_rc}{selenium_server_proc}->kill("KILL");
- my $child = Child->new(sub {
- system('ssh', $self->{selenium_rc}{host}, 'vncserver', '-kill',
+ if (my $proc = delete $self->{selenium_rc}{selenium_server_proc}) {
+ my $url = sprintf
+ "http://%s:%s/selenium-server/driver/?cmd=shutDownSeleniumServer",
+ $self->{selenium_rc}{host}, $self->{selenium_rc}{port};
+ eval { get($url); }; # will fail if it never started
+ delete $self->{src};
+ $proc->kill("KILL");
+ }
+ if (delete $self->{selenium_rc}{xvnc_started}) {
+ my $host = $self->{selenium_rc}{host};
+ my @do_ssh = $host eq 'localhost' ? () : ('ssh', $host);
+ Child->new(sub {
+ exec(@do_ssh, 'vncserver', '-kill',
":$self->{selenium_rc}{xvnc_display}");
- }
- );
- my $proc = $child->start;
- $proc->wait;
+ })->start->wait;
+ }
}
sub start_app_server {