X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTest%2FWWW%2FSelenium%2FCatalyst.pm;h=6da63e47b4a89c74a9625b4e823e5ef0e9f506e2;hb=3a859d5cc5754cf48dc06a4af98364e8fbb08619;hp=96807ffef346c3471ff11afb858e31d3e2322d9f;hpb=8f552b3b1a93a93723b1fe30461bed018536d9b9;p=catagits%2FTest-WWW-Selenium-Catalyst.git diff --git a/lib/Test/WWW/Selenium/Catalyst.pm b/lib/Test/WWW/Selenium/Catalyst.pm index 96807ff..6da63e4 100644 --- a/lib/Test/WWW/Selenium/Catalyst.pm +++ b/lib/Test/WWW/Selenium/Catalyst.pm @@ -24,7 +24,7 @@ Test::WWW::Selenium::Catalyst - Test your Catalyst application with Selenium =cut -our $VERSION = '0.03'; +our $VERSION = '0.06'; =head1 DEVELOPERISH RELEASE @@ -102,13 +102,13 @@ and it's killed when your test exits. If wish to manage a selenium server yourself, (for instance you wish to start up a server once and run a number of tests against it) pass C<-no_selenium_server> to import: - use Test::WWW::Selenium 'MyApp' + use Test::WWW::Selenium 'MyApp', -no_selenium_server => 1 Along a similar vein you can also pass command line arguments to the selenium server via C<-selenium_args>: - use Test::WWW::Selenium 'MyApp' + use Test::WWW::Selenium 'MyApp', -selenium_args => "-singleWindow -port 4445" =head2 sel_pid @@ -174,8 +174,17 @@ sub import { if(defined $d){ $DEBUG = $d; } + + $args{-selenium_args} ||= '-singleWindow'; + + if ($ENV{SELENIUM_SERVER}) { + $args{-no_selenium_server} = 1; + } + elsif ($ENV{SELENIUM_PORT}) { + $args{-selenium_args} .= " -port " . $ENV{SELENIUM_PORT}; + } - unless ($args{-no_seleniun_server}) { + unless ($args{-no_selenium_server}) { $class->_start_server($args{-selenium_args}) or croak "Couldn't start selenium server"; } return 1; @@ -220,6 +229,19 @@ sub start { my $sel_class = delete $args->{selenium_class} || 'Test::WWW::Selenium'; my $sel; + if ($ENV{SELENIUM_SERVER}) { + my $uri = $ENV{SELENIUM_SERVER}; + $uri =~ s!^(?:http://)?!http://!; + $uri = new URI($uri); + $args->{selenium_host} = $uri->host; + $args->{selenium_port} = $uri->port; + } + elsif ($ENV{SELENIUM_PORT}) { + $args->{selenium_port} = $ENV{SELENIUM_PORT}; + } + + my $sel_host = delete $args->{selenium_host} || 'localhost'; + my $sel_port = delete $args->{selenium_port} || 4444; while(!$sel && $tries--){ sleep 1; diag("Waiting for selenium server to start") @@ -227,8 +249,8 @@ sub start { eval { $sel = $sel_class->new( - host => delete $args->{selenium_host} || 'localhost', - port => delete $args->{selenium_port} || 4444, + host => $sel_host, + port => $sel_port, browser => '*firefox', browser_url => $uri, auto_stop => 0, @@ -246,7 +268,9 @@ END { if($sel_pid){ if($www_selenium){ diag("Shutting down Selenium Server $sel_pid") if $DEBUG; - $www_selenium->do_command('shutDown'); + $www_selenium->stop(); + # This can fail if a page hasn't been requested yet. + eval { $www_selenium->do_command('shutDownSeleniumServer') }; undef $www_selenium; } diag("Killing Selenium Server $sel_pid") if $DEBUG; @@ -340,7 +364,8 @@ Thanks in advance for your contributions! =head1 ACKNOWLEDGEMENTS -Thanks for mst for getting on my case to actually write this thing :) +Thanks for mst for getting on my (jrockway's) case to actually write this thing +:) =head1 COPYRIGHT & LICENSE