blib/lib/Test/Story/Fixture/Selenium.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 52 CC 5 SCAR 28.7
CC
5
Cov
0%
selenium
30.0
page_mapping
2.0
goto_page
2.0
CRAP 17.6
1 package Test::Story::Fixture::Selenium;
2 use Moose::Role;
3 use WWW::Selenium;
4 our @EXCLUDE_METHODS = qw(
5 page_mapping
6 selenium_class
7 selenium
8 );
9  
10 before 'DEMOLISH' => sub {
11 my $self = shift;
12 if (exists $self->ctxt->{selenium}) {
13 $self->ctxt->{selenium}->stop();
14 }
15 };
16  
17 has 'selenium_class' => (
18 is => 'rw',
19 required => 1,
20 isa => 'Str',
21 default => sub { "WWW::Selenium"; },
22 lazy => 1,
23 );
24  
25 sub page_mapping {
26 my $self = shift;
27 my ($url) = @_;
28 my $base = $self->_get_metavar('selenium.browser_url');
29 $base =~ s/\/$//;
30 return "$base$url";
31 }
32  
33 sub selenium {
34 my $self = shift;
35  
36 return $self->ctxt->{selenium}
37 if (exists $self->ctxt->{selenium});
38  
39 my %args = (
40 host => $self->_get_metavar('selenium.server'),
41 port => $self->_get_metavar('selenium.port'),
42 browser => $self->_get_metavar('selenium.browser'),
43 browser_url => $self->_get_metavar('selenium.browser_url'),
44 );
45  
46 foreach my $key (keys %args) {
47 delete $args{$key} unless ($args{$key});
48 }
49  
50 $args{browser} = "*$args{browser}" if (exists $args{browser});
51  
52 # Create, save and return a selenium object for this appliance
53 my $class = $self->selenium_class;
54 eval "use $class;";
55 die "$@\n" if $@;
56 $self->ctxt->{selenium} = $class->new( %args );
57 $self->ctxt->{selenium}->start();
58 return $self->ctxt->{selenium};
59 }
60  
61 =head1 FIXTURE ACTIONS
62  
63 =cut
64  
65 =head2 goto page
66  
67 goto page: /some/url
68 goto page: PageName
69  
70 Sets the current browser context to a page, either using the absolute path supplied, or
71 using an abstract page name as defined by the page_mapping hash. Either set this at run-time,
72 or override it in a subclass.
73  
74 =cut
75  
76 sub goto_page {
77 my $self = shift;
78 my ($page) = @_;
79  
80 $self->selenium->open( $self->page_mapping($page) );
81 }
82  
83 1;
84 __END__