Subject: | Patch allowing an external Selenium server to be used |
It can be useful to use an already running external Selenium server for testing
for example to run the catalyst app on a server, while Selenium and thus the
controlled browser is running on the developer's machine.
The patch allows this by setting an environment variable
(EXTERNAL_SELENIUM, but I don't really like that name), though long-term
I'd more like to move starting of the Selenium server to object instantiation (like
the Catalyst server), so the choice of which Selenium server to use can be put
into the application.
Subject: | Test-WWW-Selenium-Catalyst-external-selenium.diff |
diff -Naur Test-WWW-Selenium-Catalyst-0.01/Makefile.PL Test-WWW-Selenium-Catalyst-0.02/Makefile.PL
--- Test-WWW-Selenium-Catalyst-0.01/Makefile.PL 2007-05-27 10:20:09.000000000 +0200
+++ Test-WWW-Selenium-Catalyst-0.02/Makefile.PL 2008-02-13 15:32:29.000000000 +0100
@@ -14,6 +14,7 @@
'Test::WWW::Selenium' => 0,
'Test::More' => 0,
'Catalyst::Utils' => 0,
+ 'Sys::Hostname::FQDN' => 0,
);
auto_install();
WriteAll();
diff -Naur Test-WWW-Selenium-Catalyst-0.01/lib/Test/WWW/Selenium/Catalyst.pm Test-WWW-Selenium-Catalyst-0.02/lib/Test/WWW/Selenium/Catalyst.pm
--- Test-WWW-Selenium-Catalyst-0.01/lib/Test/WWW/Selenium/Catalyst.pm 2008-02-07 14:54:34.000000000 +0100
+++ Test-WWW-Selenium-Catalyst-0.02/lib/Test/WWW/Selenium/Catalyst.pm 2008-02-13 15:29:45.000000000 +0100
@@ -7,6 +7,7 @@
use Test::WWW::Selenium;
use Test::More;
use Catalyst::Utils;
+use Sys::Hostname::FQDN qw(fqdn);
BEGIN { $ENV{CATALYST_ENGINE} ||= 'HTTP'; }
@@ -124,13 +125,20 @@
}
# if it's something else, leave the CATALYST_DEBUG setting in tact
- _start_server() or croak "Couldn't start selenium server";
+ _start_server() or croak "Couldn't start selenium server" unless $ENV{EXTERNAL_SELENIUM};
return 1;
}
sub start {
my $class = shift;
my $args = shift || {};
+ my $host = 'localhost';
+ my $port = 4444;
+ my $catalyst_host = 'localhost';
+ if ($ENV{EXTERNAL_SELENIUM}) {
+ ($host, $port) = split /:/, $ENV{EXTERNAL_SELENIUM};
+ $catalyst_host = fqdn;
+ }
# start a Catalyst MyApp server
eval("use $app");
@@ -143,7 +151,7 @@
exit 0;
};
diag("Catalyst server running in $$") if $DEBUG;
- $app->run('3000', 'localhost');
+ $app->run('3000', $catalyst_host);
exit 1;
}
$app_pid = $pid;
@@ -158,10 +166,10 @@
eval {
$sel = Test::WWW::Selenium->
- new(host => 'localhost',
- port => 4444,
+ new(host => $host,
+ port => $port,
browser => $args->{browser} || '*firefox',
- browser_url => 'http://localhost:3000/',
+ browser_url => "http://$catalyst_host:3000/",
auto_stop => 0,
);
};
@@ -174,9 +182,12 @@
END {
if($www_selenium){
- diag("Shutting down Selenium Server $sel_pid") if $DEBUG;
- $www_selenium->do_command('shutDown');
- undef $www_selenium;
+ $www_selenium->stop();
+ if($sel_pid){
+ diag("Shutting down Selenium Server $sel_pid") if $DEBUG;
+ $www_selenium->do_command('shutDown');
+ }
+ undef $www_selenium;
}
if($sel_pid){
diag("Killing Selenium Server $sel_pid") if $DEBUG;