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

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