--- /dev/null
+package Test::Harness::Selenium;
+use strictures 1;
+
+use File::Find;
+use WWW::Selenium;
+use HTML::TableExtract;
+use IO::All;
+
+use Test::Builder;
+BEGIN {
+ package Test::Builder;
+
+ use Class::Method::Modifiers;
+ use ExtUtils::MakeMaker qw(prompt);
+
+ if (!$ENV{AUTOMATED_TESTING}) {
+ around ok => sub {
+ my ($orig, $self) = (shift, shift);
+ my $res = $self->$orig(@_);
+ unless ($res) {
+ if ('y' eq prompt "Well that didn't work, did it. Bail out?", 'y') {
+ exit 255;
+ }
+ }
+ return $res;
+ };
+ }
+}
+
+sub test_directory {
+ my ($self) = @_;
+ my @tests = File::Find::Rule->file()->name('*.html')->in($self->{dir});
+ $self->run_tests_for($_) for @tests;
+}
+
+sub run_tests_for {
+ my ($self, $html_file) = @_;
+ my $rows = $self->get_rows_for($html_file);
+ my $src = WWW::Selenium->new(
+ host => $args->{host},
+ port => $args->{port},
+ browser_url => $args->{browser_url},
+ );
+ $src->run_test_table($rows);
+}
+
+my $te = HTML::TableExtract->new;
+sub get_rows_for {
+ my ($self, $html_file) = @_;
+ my $html = io($html_file)->all;
+ $te->parse($html);
+ my $table = ($te->tables)[0];
+ my @rows = map {
+ [ map { $_ eq "\240" ? () : $_ } @$_ ]
+ } $table->rows;
+ return \@rows;
+}
+
+1;
--- /dev/null
+# (c) 2010 Matt S Trout (mst)
+# same license as perl
+# mail ideas, suggestions and flames to mst (at) shadowcat.co.uk
+# proof of concept only
+# no warranty, express or implied
+#
+# vnc4server :21
+# DISPLAY=:21 perl -MAlien::SeleniumRC -e 'Alien::SeleniumRC::start'
+
+use strict;
+use warnings;
+use Test::More qw(no_plan);
+use Socialtext::WikiFixture::Selenese;
+use HTML::TableExtract;
+
+# HTML ripped from http://seleniumhq.org/docs/05_selenium_rc.html#from-selense-to-a-program
+
+my $html = <<END;
+<html>
+<body>
+<table border="1" class="docutils" id="google-search-example">
+<colgroup>
+<col width="32%" />
+<col width="47%" />
+<col width="21%" />
+</colgroup>
+<tbody valign="top">
+<tr><td>open</td>
+<td>/</td>
+
+<td> </td>
+</tr>
+<tr><td>type</td>
+<td>q</td>
+<td>selenium rc</td>
+</tr>
+<tr><td>clickAndWait</td>
+<td>btnG</td>
+<td> </td>
+</tr>
+<tr><td>textLike</td>
+
+<td>Searches related to selenium rc</td>
+<td> </td>
+</tr>
+</tbody>
+</table>
+</body>
+</html>
+END
+
+my $te = HTML::TableExtract->new;
+
+$te->parse($html);
+
+my $table = ($te->tables)[0];
+
+my @rows = map {
+ [ map { $_ eq "\240" ? () : $_ } @$_ ]
+} $table->rows;
+
+$ENV{selenium_browser} = '*firefox /usr/lib/iceweasel/firefox-bin';
+
+my $wf = Socialtext::WikiFixture::Selenese->new(
+ host => 'localhost',
+ port => $< + 6900,
+ browser_url => 'http://www.google.com'
+);
+
+$wf->run_test_table(\@rows);
--- /dev/null
+use Test::Builder;
+BEGIN {
+ package Test::Builder;
+
+ use Class::Method::Modifiers;
+ use ExtUtils::MakeMaker qw(prompt);
+
+ if (!$ENV{AUTOMATED_TESTING}) {
+ around ok => sub {
+ my ($orig, $self) = (shift, shift);
+ my $res = $self->$orig(@_);
+ unless ($res) {
+ if ('y' eq prompt "Well that didn't work, did it. Bail out?", 'y') {
+ exit 255;
+ }
+ }
+ return $res;
+ };
+ }
+}
+
+my $CAT_SERVER_PORT = 15000 + $<;
+my $VNC_SERVER_PORT = 5900 + $<;
+my $SEL_SERVER_PORT = 6900 + $<;
+
+sub gimme_table ($file) {
+ my $te = HTML::TableExtract->new;
+ $te->parse(do { local (@ARGV, $/) = ($file); <> });
+ [ do {
+ my @r = map {
+ [ map { (!defined or $_ eq "\240") ? () : $_ } @$_ ]
+ } ($te->tables)[0]->rows;
+ shift @r; @r;
+ }
+ ]
+}
+
+sub start_server ($port) {
+ my $server = Proc::Background->new(
+ {
+ die_upon_destroy => 1
+ },
+ 'script/app_server.pl', '-p', $port
+ );
+ sleep 3;
+ $server;
+}
+
+sub setup_selenium ($system, $port, $browser, $server_url) {
+ Socialtext::WikiFixture::Selenese->new(
+ selenium => do { my $s = Test::WWW::Selenium->new(
+ host => $system,
+ port => $port,
+ browser => $browser,
+ browser_url => $server_url,
+ ); $s->start; $s }
+ );
+}
+
+--- t/sel-local-lib/lib/perl5/Socialtext/WikiFixture/Selenese.pm 2007-06-21 18:28:37.000000000 -0400
++++ t/sel-overrides/Socialtext/WikiFixture/Selenese.pm 2010-06-29 14:11:17.000000000 -0400
+@@ -128,7 +128,7 @@
+ }
+
+ # Try to guess _ok methods
+- $command .= '_ok' if { map { $_ => 1 } qw(open type) }->{$command};
++ $command .= '_ok' if { map { $_ => 1 } qw(open type click) }->{$command};
+ $self->$command($opt1, $opt2);
+ }
+
+@@ -149,6 +149,12 @@
+ $command = lc($1) . '_like';
+ }
+
++ # mst is guessing.
++
++ if ($command =~ /^(?:assert|verify)_(\w+)$/) {
++ $command = lc($1) . '_is';
++ }
++
+ return $command;
+ }
+
+@@ -200,6 +206,16 @@
+ $sel->wait_for_page_to_load_ok($self->{selenium_timeout}, @args);
+ }
+
++sub select_and_wait {
++ my ($self, $opt1, $opt2) = @_;
++ my $sel = $self->{selenium};
++
++ my @args;
++ push @args, $opt2 if $opt2;
++ $sel->select_ok($opt1, @args);
++ $sel->wait_for_page_to_load_ok($self->{selenium_timeout}, @args);
++}
++
+ =head2 text_present_like()
+
+ Search entire body for given text
+