Merge git://github.com/hissohathair/test-www-selenium-catalyst.git
Tomas Doran [Fri, 16 Sep 2011 08:00:32 +0000 (09:00 +0100)]
Changes
MANIFEST.SKIP
Makefile.PL
lib/Test/WWW/Selenium/Catalyst.pm
t/01-live.t
t/lib/TestApp.pm
t/lib/TestApp/Controller/Root.pm

diff --git a/Changes b/Changes
index 7b8366e..bfa7276 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,5 @@
 Revision history for Test-WWW-Selenium-Catalyst
 
-0.07 - 2009/09/10
  - Switch shutDown to shutDownSeleniumServer, which is present in all versions of
    SeleniumRC but is the only shut down command that works from 1.0 on.
 
index 30dfa18..265cb99 100644 (file)
@@ -33,3 +33,5 @@
 
 svn.authors
 ^\.git
+
+^Test-WWW-Selenium-Catalyst-.*
index 48d5d60..32ad153 100644 (file)
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use inc::Module::Install;
+use inc::Module::Install 0.91;
 
 name          'Test-WWW-Selenium-Catalyst';
 perl_version  '5.008000';
@@ -15,5 +15,6 @@ requires(
 );
 
 test_requires 'IPC::Cmd' => '0.42';
+test_requires 'Test::More' => '0.92';
 
 WriteAll();
index 071e427..6da63e4 100644 (file)
@@ -24,7 +24,7 @@ Test::WWW::Selenium::Catalyst - Test your Catalyst application with Selenium
 
 =cut
 
-our $VERSION = '0.07';
+our $VERSION = '0.06';
 
 =head1 DEVELOPERISH RELEASE
 
@@ -174,6 +174,15 @@ 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_selenium_server}) {
       $class->_start_server($args{-selenium_args}) or croak "Couldn't start selenium server";
@@ -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,
@@ -247,7 +269,8 @@ END {
         if($www_selenium){
             diag("Shutting down Selenium Server $sel_pid") if $DEBUG;
             $www_selenium->stop();
-            $www_selenium->do_command('shutDownSeleniumServer');
+            # 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;
@@ -341,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
 
index 0cb2d87..9e92ad8 100644 (file)
@@ -2,7 +2,7 @@
 # 01-live.t 
 # Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
 
-use Test::More tests => 80;
+use Test::More;
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
@@ -10,7 +10,8 @@ use IPC::Cmd qw/can_run/;
 
 my $have_apps = 
   can_run('java') &&
-  ( can_run('firefox') || can_run('firefox-bin') );
+  ( can_run('firefox') || can_run('firefox-bin') ) ||
+  $ENV{WE_HAVE_SELENIUM};
                 
 SKIP: {
   unless ($have_apps) {
@@ -34,7 +35,7 @@ SKIP: {
       } ); 
     };
 
-    skip $@, 80 if $@;
+    skip $@, 79 if $@;
 
     $sel->open_ok('/');
     $sel->text_is("link=Click here", "Click here");
@@ -51,3 +52,5 @@ SKIP: {
     }
   }
 }
+
+done_testing;
index bd5a456..659bd80 100755 (executable)
@@ -1,4 +1,4 @@
-package TestApp;\r
-use Catalyst;\r
-__PACKAGE__->setup; \r
-1;\r
+package TestApp;
+use Catalyst;
+__PACKAGE__->setup; 
+1;
index 1e6ed15..9458c14 100755 (executable)
@@ -1,56 +1,56 @@
-#!/usr/bin/perl\r
-# Root.pm \r
-# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>\r
-\r
-package TestApp::Controller::Root;\r
-use base qw(Catalyst::Controller);\r
-__PACKAGE__->config->{namespace} = q{};\r
-my @words = qw(foo bar baz bat qux quux);\r
-\r
-sub index : Private {\r
-    my ($self, $c, @args) = @_;\r
-    my $words = $c->uri_for('/words');\r
-    $c->response->body(<<"HERE");\r
-<html>\r
-<head>\r
-<title>TestApp</title>\r
-</head>\r
-<body>\r
-<h1>TestApp</h1>\r
-<p>This is the TestApp.</p>\r
-<p><a href="$words">Click here</a> to <i>see</i> some words.</p>\r
-</body>\r
-</html>    \r
-HERE\r
-}\r
-\r
-sub words : Local {\r
-    my ($self, $c, $times) = @_;\r
-    $times ||= 0;\r
-    my $html = <<"HEADER";\r
-<html>\r
-<head>\r
-<title>TestApp</title>\r
-</head>\r
-<body>\r
-<h1>TestApp &lt;&lt; Words</h1>\r
-<p>Here you'll find all things "words" printed $times time(s)!</p>\r
-<ul>\r
-HEADER\r
-    local $" = q{ }; # single space\r
-    $html .= " <li>$_: @words</li>\n" for 1..$times;\r
-    $html .= <<"FOOTER"; \r
-</ul>\r
-</body>\r
-</html>\r
-FOOTER\r
-    $c->response->body($html);\r
-}\r
-\r
-sub null : Path('/favicon.ico'){\r
-    my ($self, $c) = @_;\r
-    $c->response->status(404); # doesn't exist\r
-}\r
-\r
-1; # true.\r
-\r
+#!/usr/bin/perl
+# Root.pm 
+# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
+
+package TestApp::Controller::Root;
+use base qw(Catalyst::Controller);
+__PACKAGE__->config->{namespace} = q{};
+my @words = qw(foo bar baz bat qux quux);
+
+sub index : Private {
+    my ($self, $c, @args) = @_;
+    my $words = $c->uri_for('/words');
+    $c->response->body(<<"HERE");
+<html>
+<head>
+<title>TestApp</title>
+</head>
+<body>
+<h1>TestApp</h1>
+<p>This is the TestApp.</p>
+<p><a href="$words">Click here</a> to <i>see</i> some words.</p>
+</body>
+</html>    
+HERE
+}
+
+sub words : Local {
+    my ($self, $c, $times) = @_;
+    $times ||= 0;
+    my $html = <<"HEADER";
+<html>
+<head>
+<title>TestApp</title>
+</head>
+<body>
+<h1>TestApp &lt;&lt; Words</h1>
+<p>Here you'll find all things "words" printed $times time(s)!</p>
+<ul>
+HEADER
+    local $" = q{ }; # single space
+    $html .= " <li>$_: @words</li>\n" for 1..$times;
+    $html .= <<"FOOTER"; 
+</ul>
+</body>
+</html>
+FOOTER
+    $c->response->body($html);
+}
+
+sub null : Path('/favicon.ico'){
+    my ($self, $c) = @_;
+    $c->response->status(404); # doesn't exist
+}
+
+1; # true.
+