| 1 | package Selenium::ActionChains; | ||||||||||
| 2 | 1 | $Selenium::ActionChains::VERSION = '1.50'; | |||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Action chains for Selenium::Remote::Driver | ||||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | 1 | has 'driver' => ( is => 'ro', ); | |||||||||
| 11 | |||||||||||
| 12 | has 'actions' => ( | ||||||||||
| 13 | is => 'lazy', | ||||||||||
| 14 | 0 | ▶ | builder => sub { [] }, | ||||||||
|
Subroutine
_build_actions: not called CC=1 SCAR=6.9
| |||||||||||
| 15 | 1 | clearer => 1, | |||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub perform { | ||||||||
|
Subroutine
perform: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 19 | 0 | my $self = shift; | |||||||||
| 20 | 0 | foreach my $action ( @{ $self->actions } ) { | |||||||||
| 21 | 0 | $action->(); | |||||||||
| 22 | } | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub click { | ||||||||
|
Subroutine
click: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 26 | 0 | my $self = shift; | |||||||||
| 27 | 0 | my $element = shift; | |||||||||
| 28 | 0 | ▶ | if ($element) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | $self->move_to_element($element); | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | # left click | ||||||||||
| 33 | 0 | ▶ | push @{ $self->actions }, sub { $self->driver->click('LEFT') }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 34 | 0 | $self; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub click_and_hold { | ||||||||
|
Subroutine
click_and_hold: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 38 | 0 | my $self = shift; | |||||||||
| 39 | 0 | my $element = shift; | |||||||||
| 40 | 0 | ▶ | if ($element) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | $self->move_to_element($element); | |||||||||
| 42 | } | ||||||||||
| 43 | 0 | ▶ | push @{ $self->actions }, sub { $self->driver->button_down }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 44 | 0 | $self; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub context_click { | ||||||||
|
Subroutine
context_click: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 48 | 0 | my $self = shift; | |||||||||
| 49 | 0 | my $element = shift; | |||||||||
| 50 | 0 | ▶ | if ($element) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | $self->move_to_element($element); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | # right click | ||||||||||
| 55 | 0 | ▶ | push @{ $self->actions }, sub { $self->driver->click('RIGHT') }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 56 | 0 | $self; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub double_click { | ||||||||
|
Subroutine
double_click: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 60 | 0 | my $self = shift; | |||||||||
| 61 | 0 | my $element = shift; | |||||||||
| 62 | 0 | ▶ | if ($element) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $self->move_to_element($element); | |||||||||
| 64 | } | ||||||||||
| 65 | 0 | ▶ | push @{ $self->actions }, sub { $self->driver->double_click }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | 0 | $self; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub release { | ||||||||
|
Subroutine
release: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 70 | 0 | my $self = shift; | |||||||||
| 71 | 0 | my $element = shift; | |||||||||
| 72 | 0 | ▶ | if ($element) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | $self->move_to_element($element); | |||||||||
| 74 | } | ||||||||||
| 75 | 0 | ▶ | push @{ $self->actions }, sub { $self->driver->button_up }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 76 | 0 | $self; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | ▶ | sub drag_and_drop { | ||||||||
|
Subroutine
drag_and_drop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 80 | 0 | my $self = shift; | |||||||||
| 81 | 0 | my ( $source, $target ) = @_; | |||||||||
| 82 | 0 | $self->click_and_hold($source); | |||||||||
| 83 | 0 | $self->release($target); | |||||||||
| 84 | 0 | $self; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | sub drag_and_drop_by_offset { | ||||||||
|
Subroutine
drag_and_drop_by_offset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 88 | 0 | my $self = shift; | |||||||||
| 89 | 0 | my ( $source, $xoffset, $yoffset ) = @_; | |||||||||
| 90 | 0 | $self->click_and_hold($source); | |||||||||
| 91 | 0 | $self->move_by_offset( $xoffset, $yoffset ); | |||||||||
| 92 | 0 | $self->release($source); | |||||||||
| 93 | 0 | $self; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | sub move_to_element { | ||||||||
|
Subroutine
move_to_element: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 97 | 0 | my $self = shift; | |||||||||
| 98 | 0 | my $element = shift; | |||||||||
| 99 | 0 | push @{ $self->actions }, | |||||||||
| 100 | 0 | ▶ | sub { $self->driver->move_to( element => $element ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 101 | 0 | $self; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | sub move_by_offset { | ||||||||
|
Subroutine
move_by_offset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 105 | 0 | my $self = shift; | |||||||||
| 106 | 0 | my ( $xoffset, $yoffset ) = @_; | |||||||||
| 107 | 0 | ▶ | push @{ $self->actions }, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 108 | 0 | $self->driver->move_to( xoffset => $xoffset, yoffset => $yoffset ); | |||||||||
| 109 | 0 | }; | |||||||||
| 110 | 0 | $self; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 0 | ▶ | sub move_to_element_with_offset { | ||||||||
|
Subroutine
move_to_element_with_offset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 114 | 0 | my $self = shift; | |||||||||
| 115 | 0 | my ( $element, $xoffset, $yoffset ) = @_; | |||||||||
| 116 | 0 | ▶ | push @{ $self->actions }, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 117 | 0 | $self->driver->move_to( | |||||||||
| 118 | element => $element, | ||||||||||
| 119 | xoffset => $xoffset, | ||||||||||
| 120 | yoffset => $yoffset | ||||||||||
| 121 | ); | ||||||||||
| 122 | 0 | }; | |||||||||
| 123 | 0 | $self; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 0 | ▶ | sub key_down { | ||||||||
|
Subroutine
key_down: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 127 | 0 | my ( $self, $value, $element ) = @_; | |||||||||
| 128 | |||||||||||
| 129 | #DWIM | ||||||||||
| 130 | 0 | ▶ | $value = [$value] unless ref $value eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | |||||||||||
| 132 | 0 | ▶ | $self->click($element) if defined $element; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | 0 | foreach my $v (@$value) { | |||||||||
| 134 | 0 | push @{ $self->actions }, | |||||||||
| 135 | 0 | ▶ | sub { $self->driver->general_action( actions => [ { type => 'key', id => 'key', actions => [ { type => 'keyDown', value => $v } ] } ] ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 136 | } | ||||||||||
| 137 | 0 | return $self; | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | 0 | ▶ | sub key_up { | ||||||||
|
Subroutine
key_up: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 141 | 0 | my ( $self, $value, $element ) = @_; | |||||||||
| 142 | |||||||||||
| 143 | #DWIM | ||||||||||
| 144 | 0 | ▶ | $value = [$value] unless ref $value eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | |||||||||||
| 146 | 0 | ▶ | $self->click($element) if defined $element; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 147 | 0 | foreach my $v (@$value) { | |||||||||
| 148 | 0 | push @{ $self->actions }, | |||||||||
| 149 | 0 | ▶ | sub { $self->driver->general_action( actions => [ { type => 'key', id => 'key', actions => [ { type => 'keyUp', value => $v } ] } ] ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 150 | } | ||||||||||
| 151 | 0 | return $self; | |||||||||
| 152 | } | ||||||||||
| 153 | |||||||||||
| 154 | 0 | ▶ | sub send_keys { | ||||||||
|
Subroutine
send_keys: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 155 | 0 | my ($self,$keys) =@_; | |||||||||
| 156 | |||||||||||
| 157 | # Do nothing if there are no keys to send | ||||||||||
| 158 | 0 | ▶ | return unless $keys; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | |||||||||||
| 160 | # DWIM | ||||||||||
| 161 | 0 | ▶ | $keys = [split('',$keys)] unless ref $keys eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 162 | |||||||||||
| 163 | 0 | push @{ $self->actions }, | |||||||||
| 164 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 165 | 0 | foreach my $key (@$keys) { | |||||||||
| 166 | 0 | $self->key_down($key, $self->driver->get_active_element); | |||||||||
| 167 | 0 | $self->key_up($key, $self->driver->get_active_element); | |||||||||
| 168 | } | ||||||||||
| 169 | 0 | }; | |||||||||
| 170 | 0 | $self; | |||||||||
| 171 | } | ||||||||||
| 172 | |||||||||||
| 173 | 0 | ▶ | sub send_keys_to_element { | ||||||||
|
Subroutine
send_keys_to_element: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 174 | 0 | my ($self, $element, $keys) =@_; | |||||||||
| 175 | |||||||||||
| 176 | # Do nothing if there are no keys to send | ||||||||||
| 177 | 0 | ▶ | return unless $keys; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 178 | |||||||||||
| 179 | # DWIM | ||||||||||
| 180 | 0 | ▶ | $keys = [split('',$keys)] unless ref $keys eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 181 | |||||||||||
| 182 | 0 | push @{ $self->actions }, | |||||||||
| 183 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 184 | 0 | foreach my $key (@$keys) { | |||||||||
| 185 | 0 | $self->key_down($key,$element); | |||||||||
| 186 | 0 | $self->key_up($key,$element); | |||||||||
| 187 | } | ||||||||||
| 188 | 0 | }; | |||||||||
| 189 | 0 | $self; | |||||||||
| 190 | } | ||||||||||
| 191 | |||||||||||
| 192 | 1 | 1; | |||||||||
| 193 | |||||||||||
| 194 | __END__ | ||||||||||