From: Chris Nehren Date: Wed, 12 Jan 2011 11:10:26 +0000 (-0500) Subject: add another test, almost working support for selenium RC forking and running multiple... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a5dd28039c9a4c64ad495765034f8850b675beba;p=scpubgit%2FTest-Harness-Selenium.git add another test, almost working support for selenium RC forking and running multiple tests --- diff --git a/lib/Test/Harness/Selenium.pm b/lib/Test/Harness/Selenium.pm index ecaf665..4766a28 100644 --- a/lib/Test/Harness/Selenium.pm +++ b/lib/Test/Harness/Selenium.pm @@ -1,10 +1,12 @@ 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 { @@ -32,23 +34,63 @@ sub new { 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; diff --git a/t b/t/basic.t similarity index 73% rename from t rename to t/basic.t index 6bae426..303599b 100644 --- a/t +++ b/t/basic.t @@ -4,11 +4,13 @@ use warnings; 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; diff --git a/basic.html b/t/corpus/basic.html similarity index 100% copy from basic.html copy to t/corpus/basic.html diff --git a/basic.html b/t/corpus/no_delay.html similarity index 78% rename from basic.html rename to t/corpus/no_delay.html index 28e8497..8e74511 100644 --- a/basic.html +++ b/t/corpus/no_delay.html @@ -16,13 +16,9 @@ q selenium rc -clickAndWait -btnG -  - textLike -Searches related to selenium rc +Searches related to rc