File Coverage

blib/lib/Selenium/PageObject.pm
Criterion Covered Total %
statement 28 52 53.8
branch 3 20 15.0
condition n/a
subroutine 9 16 56.2
pod 5 5 100.0
total 45 93 48.3


line stmt bran cond sub pod time code
1             # ABSTRACT: Selenium's PageObject pattern in Perl. Now your module @ISA pageObject!
2             # PODNAME: Selenium::PageObject
3              
4             package Selenium::PageObject;
5             $Selenium::PageObject::VERSION = '0.012';
6 1     1   209190 use 5.010;
  1         3  
  1         32  
7 1     1   3 use strict;
  1         1  
  1         22  
8 1     1   4 use warnings;
  1         1  
  1         17  
9              
10 1     1   4 use Carp;
  1         1  
  1         46  
11 1     1   12 use Scalar::Util qw(reftype blessed);
  1         2  
  1         42  
12 1     1   3 use Try::Tiny;
  1         2  
  1         43  
13              
14 1     1   429 use Selenium::Remote::WDKeys; #Needed to send things like tabs for navigation
  1         449  
  1         39  
15 1     1   365 use Selenium::Element;
  1         2  
  1         391  
16              
17              
18             sub new {
19 2     2 1 633 my ($class,$driver,$uri) = @_;
20 2 50       4 confess("Constructor must be called statically, not by an instance") if ref($class);
21 2 50       3 confess("Driver must be an instance of Selenium::Remote::Driver or WWW::Selenium") if !( grep {defined(blessed($driver)) && $_ eq blessed($driver)} qw(Selenium::Remote::Driver WWW::Selenium) );
  4 50       463  
22              
23 0           my $self = {
24             'drivertype' => blessed($driver) eq 'WWW::Selenium',
25             'driver' => $driver,
26             'page' => $uri
27             };
28              
29 0 0         $self->{'drivertype'} ? $driver->open($uri) : $driver->get($uri); #Get initial page based on what type of driver used
30              
31 0           bless $self, $class;
32 0           return $self;
33             }
34              
35              
36             sub driver {
37 0     0 1   my $self = shift;
38 0           return $self->{'driver'};
39             }
40              
41              
42             sub getElement {
43 0     0 1   my ($self,$selector,$selectortype) = @_;
44 0           my $element;
45 0 0         if ($self->{'drivertype'}) {
46 0 0         $element = $self->{'driver'}->is_element_present("$selectortype=$selector") ? "$selectortype=$selector" : undef;
47             } else {
48             try {
49 0     0     $element = $self->{'driver'}->find_element($selector,$selectortype);
50             } catch {
51 0     0     carp "# $_ \n";
52 0           $element = undef;
53             }
54 0           }
55 0 0         return Selenium::Element->new($element,$self->{'drivertype'} ? $self->{'driver'} : $self->{'drivertype'},[$selector,$selectortype]);
56             }
57              
58              
59             sub getElements {
60 0     0 1   my ($self,$selector,$selectortype) = @_;
61 0           my $elements = [];
62 0 0         confess ("WWW::Selenium is designed to work with single elements. Consider refining your selectors and looping instead.") if $self->{'drivertype'};
63             try {
64 0     0     @$elements = $self->{'driver'}->find_elements($selector,$selectortype);
65 0           };
66 0 0         return map {Selenium::Element->new($_,$self->{'drivertype'} ? $self->{'driver'} : $self->{'drivertype'},[$selector,$selectortype])} @$elements;
  0            
67             }
68              
69              
70             sub tab {
71 0     0 1   my $self = shift;
72             #9 is VK_TAB
73 0 0         $self->{'drivertype'} ? $self->driver->key_press_native(9) : $self->driver->send_keys_to_active_element(KEYS->{'tab'});
74             }
75              
76             1;
77              
78             __END__