d4eda0e335f11d09c450fd713fd7677e9c63c80c
[scpubgit/Test-Harness-Selenium.git] / lib / Test / Harness / Selenium.pm
1 package Test::Harness::Selenium;
2 use strictures 1;
3
4 use File::Find;
5 use Socialtext::WikiFixture::Selenese;
6 use HTML::TableExtract;
7 use IO::All;
8
9 use Test::Builder;
10 BEGIN {
11   package Test::Builder;
12
13   use Class::Method::Modifiers;
14   use ExtUtils::MakeMaker qw(prompt);
15
16   if (!$ENV{AUTOMATED_TESTING}) {
17     around ok => sub {
18       my ($orig, $self) = (shift, shift);
19       my $res = $self->$orig(@_);
20       unless ($res) {
21         if ('y' eq prompt "Well that didn't work, did it. Bail out?", 'y') {
22           exit 255;
23         }
24       }
25       return $res;
26     };
27   }
28 }
29
30 sub new {
31   my ($class, $self) = @_;
32   bless $self, $class;
33 }
34
35 sub test_directory {
36   my ($self, $dir) = @_;
37   my @tests = File::Find::Rule->file()->name('*.html')->in($dir);
38   $self->run_tests_for($_) for @tests;
39 }
40
41 sub run_tests_for {
42   my ($self, $html_file) = @_;
43   my $rows = $self->get_rows_for($html_file);
44   my $src = Socialtext::WikiFixture::Selenese->new(
45     host => $self->{host},
46     port => $self->{port},
47     browser => $self->{browser},
48     browser_url => $self->{browser_url},
49   );
50   $src->run_test_table($rows);
51 }
52
53 my $te = HTML::TableExtract->new;
54 sub get_rows_for {
55   my ($self, $html_file) = @_;
56   my $html = io($html_file)->all;
57   $te->parse($html);
58   my $table = ($te->tables)[0];
59   my @rows = map {
60     [ map { $_ eq "\240" ? () : $_ } @$_ ]
61   } $table->rows;
62   return \@rows;
63 }
64
65 1;