basic working code, needs more hammering and testing
[scpubgit/Test-Harness-Selenium.git] / lib / Test / Harness / Selenium.pm
CommitLineData
676409e6 1package Test::Harness::Selenium;
2use strictures 1;
3
4use File::Find;
3749d2e5 5use Socialtext::WikiFixture::Selenese;
676409e6 6use HTML::TableExtract;
7use IO::All;
8
9use Test::Builder;
10BEGIN {
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
3749d2e5 30sub new {
31 my ($class, $self) = @_;
32 bless $self, $class;
33}
34
676409e6 35sub test_directory {
3749d2e5 36 my ($self, $dir) = @_;
37 my @tests = File::Find::Rule->file()->name('*.html')->in($dir);
676409e6 38 $self->run_tests_for($_) for @tests;
39}
40
41sub run_tests_for {
42 my ($self, $html_file) = @_;
43 my $rows = $self->get_rows_for($html_file);
3749d2e5 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},
676409e6 49 );
50 $src->run_test_table($rows);
51}
52
53my $te = HTML::TableExtract->new;
54sub 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
651;