File: Selenium.pm

package info (click to toggle)
libsocialtext-wikitest-perl 0.06-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 124 kB
  • ctags: 39
  • sloc: perl: 592; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package Test::WWW::Selenium;
use strict;
use warnings;
use base 'Exporter';
use Test::More;

our @EXPORT_OK = '$SEL';

our $SEL; # singleton

sub new {
    my ($class, %opts) = @_;
    if ($SEL) {
        $SEL->{args} = \%opts;
        return $SEL;
    }
    $SEL = { args => \%opts };
    bless $SEL, $class;
    return $SEL;
}

sub set_return_value {
    my ($self, $name, $return) = @_;
    push @{$self->{return}{$name}}, $return;
}

sub method_args_ok {
    my ($self, $name, $expected) = @_;
    my $actual = shift @{$self->{$name}};
    is_deeply $actual, $expected;
}

sub empty_ok {
    my $self = shift;
    my $ignore_extra = shift;
    for my $k (keys %$self) {
        next if $k eq 'return' or $k eq 'args';
        next if ref($self->{$k}) eq 'ARRAY' and @{$self->{$k}} == 0;
        if ($ignore_extra) {
            delete $self->{$k};
        }
        else {
            ok 0, "extra call to $k - " . ref($self->{$k});
        }
    }
    $self->{return} = {};
}

our $AUTOLOAD;
sub AUTOLOAD {
    my $name = $AUTOLOAD;
    $name =~ s/.+:://;
    return if $name eq 'DESTROY';

    my ($self, $opt1, $opt2) = @_;
    if ($opt2) {
        push @{$self->{$name}}, [$opt1, $opt2];
    }
    else {
        push @{$self->{$name}}, $opt1;
    }

    if ($self->{return}{$name}) {
        return shift @{$self->{return}{$name}};
    }
    return;
}

1;