defe00f6f8c9b410d6c1b7fd3b68e3244301dca3
[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 WWW::Selenium;
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 test_directory {
31   my ($self) = @_;
32   my @tests = File::Find::Rule->file()->name('*.html')->in($self->{dir});
33   $self->run_tests_for($_) for @tests;
34 }
35
36 sub run_tests_for {
37   my ($self, $html_file) = @_;
38   my $rows = $self->get_rows_for($html_file);
39   my $src = WWW::Selenium->new(
40     host => $args->{host},
41     port => $args->{port},
42     browser_url => $args->{browser_url},
43   );
44   $src->run_test_table($rows);
45 }
46
47 my $te = HTML::TableExtract->new;
48 sub get_rows_for {
49   my ($self, $html_file) = @_;
50   my $html = io($html_file)->all;
51   $te->parse($html);
52   my $table = ($te->tables)[0];
53   my @rows = map {
54     [ map { $_ eq "\240" ? () : $_ } @$_ ]
55   } $table->rows;
56   return \@rows;
57 }
58
59 1;