package Test::Harness::Selenium;
use strictures 1;
-use File::Find;
+use File::Find::Rule;
use Socialtext::WikiFixture::Selenese;
use HTML::TableExtract;
use IO::All;
+use Alien::SeleniumRC;
+use LWP::Simple;
use Test::More;
BEGIN {
bless $self, $class;
}
+sub start_server {
+ my($self) = @_;
+ my $server_pid = fork();
+ if($server_pid > 0) {
+ $self->{server_pid} = $server_pid;
+ 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;
+ }
+ else {
+ last;
+ }
+ }
+ die "timed out waiting for selenium server to start" if $tries == 5;
+ }
+ elsif($server_pid == 0) {
+ close STDOUT;
+ close STDERR;
+ # muttermutter, can't specify a host for selenium
+ Alien::SeleniumRC::start("-port $self->{port}");
+ }
+ else {
+ die "can't fork: $!";
+ }
+}
+
+sub stop_server {
+ my($self) = @_;
+ # okay, we're done, kill the server.
+ get("http://localhost:$self->{port}/selenium-server/driver/?cmd=shutDownSeleniumServer");
+ wait;
+}
+
sub test_directory {
my ($self, $dir) = @_;
my @tests = File::Find::Rule->file()->name('*.html')->in($dir);
- $self->run_tests_for($_) for @tests;
+ for my $test (@tests) {
+ $self->start_server;
+ $self->run_tests_for($test);
+ $self->stop_server;
+ }
}
sub run_tests_for {
my ($self, $html_file) = @_;
my $rows = $self->get_rows_for($html_file);
- my $src = Socialtext::WikiFixture::Selenese->new(
- host => $self->{host},
- port => $self->{port},
- browser => $self->{browser},
- browser_url => $self->{browser_url},
- );
- $src->run_test_table($rows);
- done_testing;
+ eval { $self->{src}->run_test_table($rows); };
}
my $te = HTML::TableExtract->new;
use lib 'lib';
use Test::Harness::Selenium;
+use Test::More;
my $s = Test::Harness::Selenium->new({
host => 'localhost',
- port => 4444,
+ port => $< + 60_000,
browser_url => 'http://www.google.com',
browser => shift,
});
-$s->run_tests_for(shift);
+$s->test_directory(shift);
+done_testing;