fixes for running against Selenium IDE-generated tests
[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::More;
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   done_testing;
52 }
53
54 my $te = HTML::TableExtract->new;
55 sub get_rows_for {
56   my ($self, $html_file) = @_;
57   my $html = io($html_file)->all;
58   $te->parse($html);
59   my $table = ($te->tables)[0];
60   my @rows = map {
61     [ map { (!defined $_ or $_ eq "\240") ? () : $_ } @$_ ]
62   } grep { defined $_->[1] } $table->rows;
63   return \@rows;
64 }
65
66 1;