don't call $sel->start, it breaks things
Jonathan Rockway [Thu, 6 Mar 2008 12:29:55 +0000 (06:29 -0600)]
t/01live.t fails with an error message telling that it couldn't start the Selenium
server for an unknown reason, despite the server running and having started a
browser. This server is also never stopped so the test never finishes because
it's waiting for child processes to exit.

It turns out that the $sel->start; call is not needed at all, and everything works
just as well without it. It's also not mentioned in Test::WWW::Selenium
documentation and examples.

The attached patch fixes this issue and gives a shot at stopping the Selenium
server by issuing a shutDown command before killing the Alien::SeleniumRC
child.

Tests run successfully for me and the module installs with this patch.

lib/Test/WWW/Selenium/Catalyst.pm

index 6ab513f..39ceeef 100644 (file)
@@ -16,6 +16,7 @@ my $DEBUG = $ENV{CATALYST_DEBUG};
 my $app; # app name (MyApp)
 my $sel_pid; # pid of selenium server
 my $app_pid; # pid of myapp server
+my $www_selenium;
 
 =head1 NAME
 
@@ -160,19 +161,23 @@ sub start {
              new(host => 'localhost',
                  port => 4444,
                  browser => $args->{browser} || '*firefox',
-                 browser_url => 'http://localhost:3000/'
+                 browser_url => 'http://localhost:3000/',
+                 auto_stop => 0,
                 );
        };
        $error = $@;
     }
+    croak "Can't start selenium: $error" if $error;
     
-    eval { $sel->start }
-      or croak "Can't start selenium: $@ (previous error: $error)";
-    
-    return $sel;
+    return $www_selenium = $sel;
 }
 
 END {
+    if($www_selenium){
+       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;
        kill 15, $sel_pid or diag "Killing Selenium: $!";