use IO::All;
use Alien::SeleniumRC;
use LWP::Simple;
+use Child;
use Test::More;
BEGIN {
}
sub new {
- my ($class, $self) = @_;
- if($self->{xvnc}) {
- $ENV{DISPLAY} = $self->{xvnc};
- my $xvnc_pid = fork();
- if(!defined $xvnc_pid) {
- die "couldn't fork xvnc: $!";
- }
- elsif($xvnc_pid) {
- $self->{xvnc_pid} = $xvnc_pid;
- }
- else {
- exec("vncserver", $self->{xvnc});
- }
+ my $class = shift;
+ my %args = @_;
+ if( $ENV{SELENIUM_RC_HOST} &&
+ $ENV{SELENIUM_RC_PORT} &&
+ $ENV{SELENIUM_RC_START} ) {
+ $args{selenium_rc}{host} = $ENV{SELENIUM_RC_HOST};
+ $args{selenium_rc}{port} = $ENV{SELENIUM_RC_PORT};
+ $args{selenium_rc}{start} = $ENV{SELENIUM_RC_START};
}
+ my $self = \%args;
bless $self, $class;
}
-sub start_server {
+sub start_selenium_server {
my($self) = @_;
- $self->{server_pid} = fork();
- if(!defined $self->{server_pid}) {
- die "can't fork: $!";
- }
- if($self->{server_pid} > 0) {
- my $tries = 0;
- while($tries < 5) {
- eval {
- $self->{src} = Socialtext::WikiFixture::Selenese->new(
- host => $self->{host},
- port => $self->{port},
- browser => $self->{browser},
- browser_url => $self->{browser_url},
- );
- };
- $tries++;
- if(!defined $self->{src}) {
- sleep 10;
+ if($self->{selenium_rc}{start}) {
+ $self->{selenium_rc}{xvnc_server_proc} = Child->new(sub {
+ system('ssh', $self->{selenium_rc}{host}, 'vncserver');
}
- else {
- last;
+ );
+ $self->{selenium_rc}{xvnc_server_proc}->start;
+ $self->{selenium_rc}{selenium_server_proc} = Child->new(sub {
+ system('ssh', $self->{selenium_rc}{host}, 'env',
+ "DISPLAY=:$self->{selenium_rc}{xvnc_display}", 'selenium-rc', '-port',
+ $self->{selenium_rc}{port} );
}
- }
- die "timed out waiting for selenium server to start" if $tries == 5;
+ );
+ $self->{selenium_rc}{selenium_server_proc}->start;
}
- elsif($self->{server_pid} == 0) {
- # muttermutter, can't specify a host for selenium
- exec("$^X -MAlien::SeleniumRC -e 'Alien::SeleniumRC::start(q{-port $self->{port}})'");
+ my $tries = 0;
+ while($tries < 5) {
+ eval {
+ $self->{src} = Socialtext::WikiFixture::Selenese->new(
+ host => $self->{selenium_rc}{host},
+ port => $self->{selenium_rc}{port},
+ browser => $self->{browser},
+ browser_url => $self->{app_base},
+ );
+ };
+ $tries++;
+ if(!defined $self->{src}) {
+ sleep 10;
+ }
+ else {
+ last;
+ }
}
+ die "timed out waiting for selenium server to start" if $tries == 5;
}
-sub stop_server {
+sub stop_selenium_server {
my($self) = @_;
# okay, we're done, kill the server.
- get("http://localhost:$self->{port}/selenium-server/driver/?cmd=shutDownSeleniumServer");
+ my $url = sprintf
+ "http://%s:%s/selenium-server/driver/?cmd=shutDownSeleniumServer",
+ $self->{selenium_rc}{host}, $self->{selenium_rc}{port};
+ get($url);
delete $self->{src};
- wait;
+ $self->{selenium_rc}{selenium_server_proc}->wait;
+ $self->{selenium_rc}{xvnc_server_proc}->wait;
+}
+
+sub start_app_server {
+ my($self) = @_;
+ $self->{app_server_proc} = Child->new(sub { exec($self->{app_server_cmd}) } );
+ $self->{app_server_proc}->start;
+}
+
+sub stop_app_server {
+ my($self) = @_;
+ $self->{app_server_proc}->complete || $self->{app_server_proc}->kill(9);
}
sub test_directory {