Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #!/usr/bin/env lines for debian/macos #481

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Revision history for Selenium-Remote-Driver

1.47 2022-05-02 TEODESIAN
- Add DWIM to inputs accepted by ActionChains send_keys, key_up & key_down, and add some docu

1.46 2021-12-04 TEODESIAN
- Document the keys of WDKEYS hash in POD. Contribution by Yuki Kimoto.

1.45 2021-10-21 TEODESIAN
- Remove ill-advised test reaching out to saucelabs at install-time, vendors are the users' problem

1.44 2021-03-26 TEODESIAN
- Remove all usage of default profiles for Firefox when in direct binary mode.

2 changes: 1 addition & 1 deletion dist.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = Selenium-Remote-Driver
version = 1.44
version = 1.47
author = George S. Baugh <[email protected]>
author = Aditya Ivaturi <[email protected]>
author = Daniel Gempesaw <[email protected]>
84 changes: 61 additions & 23 deletions lib/Selenium/ActionChains.pm
Original file line number Diff line number Diff line change
@@ -127,11 +127,12 @@ sub move_to_element_with_offset {
}

sub key_down {
my $self = shift;
my ( $value, $element ) = @_;
if ( defined($element) ) {
$self->click($element);
}
my ( $self, $value, $element ) = @_;

#DWIM
$value = [$value] unless ref $value eq 'ARRAY';

$self->click($element) if defined $element;
foreach my $v (@$value) {
push @{ $self->actions },
sub { $self->driver->general_action( actions => [ { type => 'key', id => 'key', actions => [ { type => 'keyDown', value => $v } ] } ] ) };
@@ -140,30 +141,54 @@ sub key_down {
}

sub key_up {
my $self = shift;
my ( $value, $element ) = @_;
if ( defined($element) ) {
$self->click($element);
}
my ( $self, $value, $element ) = @_;

#DWIM
$value = [$value] unless ref $value eq 'ARRAY';

$self->click($element) if defined $element;
foreach my $v (@$value) {
push @{ $self->actions },
sub { $self->driver->$self->driver->general_action( actions => [ { type => 'key', id => 'key', actions => [ { type => 'keyUp', value => $v } ] } ] ) };
sub { $self->driver->general_action( actions => [ { type => 'key', id => 'key', actions => [ { type => 'keyUp', value => $v } ] } ] ) };
}
return $self;
}

sub send_keys {
my $self = shift;
my $keys = shift;
my ($self,$keys) =@_;

# Do nothing if there are no keys to send
return unless $keys;

# DWIM
$keys = [split('',$keys)] unless ref $keys eq 'ARRAY';

push @{ $self->actions },
sub { $self->driver->get_active_element->send_keys($keys) };
sub {
foreach my $key (@$keys) {
$self->key_down($key, $self->driver->get_active_element);
$self->key_up($key, $self->driver->get_active_element);
}
};
$self;
}

sub send_keys_to_element {
my $self = shift;
my ( $element, $keys ) = @_;
push @{ $self->actions }, sub { $element->send_keys($keys) };
my ($self, $element, $keys) =@_;

# Do nothing if there are no keys to send
return unless $keys;

# DWIM
$keys = [split('',$keys)] unless ref $keys eq 'ARRAY';

push @{ $self->actions },
sub {
foreach my $key (@$keys) {
$self->key_down($key,$element);
$self->key_up($key,$element);
}
};
$self;
}

@@ -311,29 +336,37 @@ LIMITATIONS.
=head2 key_down

Sends key presses only, without releasing them.
Should be used only with modifier keys (Control, Alt, Shift)
Useful when modifier keys are requried

Will DWIM your input and accept either a string or ARRAYREF of keys.

Args:
An array ref to keys to send. Use the KEY constant from Selenium::Remote::WDKeys
The element to send keys to. If none, sends keys to the current focused element

Usage:
use Selenium::Remote::WDKeys 'KEYS';
$action_chains->key_down( [ KEYS->{'alt'} ] );
# DEFINITELY cut and paste this in without looking
$action_chains->key_down( [ KEYS->{'alt'}, KEYS->{'F4'} ] );


=head2 key_up

Releases a mofifier key.
Releases prior key presses.
Useful when modifier keys are requried

Will DWIM your input and accept either a string or ARRAYREF of keys.

Args:
An array ref to keys to send. Use the KEY constant from Selenium::Remote::WDKeys
The element to send keys to. If none, sends keys to the current focused element

Usage:
use Selenium::Remote::WDKeys 'KEYS';
# Fullscreen the foo element
my $element = $driver->find_element('foo','id');
$action_chains->key_up( [ KEYS->{'alt'} ],$element);
$action_chains->key_down( [ KEYS->{'alt'}, KEYS->{'enter'} ], $element );
$action_chains->key_up( [ KEYS->{'alt'}, KEYS->{'enter'} ], $element);


=head2 move_by_offset
@@ -388,7 +421,10 @@ Releases a held mouse_button

=head2 send_keys

Sends keys to the currently focused element
Sends keys to the currently focused element.
Essentially an alias around key_down then key_up.

Will DWIM your input and accept either a string or ARRAYREF of keys.

Args:
The keys to send
@@ -398,7 +434,9 @@ Sends keys to the currently focused element

=head2 send_keys_to_element

Sends keys to an element
Sends keys to an element in much the same fashion as send_keys.

Will DWIM your input and accept either a string or ARRAYREF of keys.

Args:
A Selenium::Remote::WebElement
76 changes: 76 additions & 0 deletions lib/Selenium/Remote/WDKeys.pm
Original file line number Diff line number Diff line change
@@ -6,6 +6,82 @@ package Selenium::Remote::WDKeys;

The constant KEYS is defined here.

=head1 SYNOPSIS

use Selenium::Remote::WDKeys;

my $space_key = KEYS->{'space'};
my $enter_key = KEYS->{'enter'};

=head1 CONSTANT KEYS

null
cancel
help
backspace
tab
clear
return
enter
shift
control
alt
pause
escape
space
page_up
page_down
end
home
left_arrow
up_arrow
right_arrow
down_arrow
insert
delete
semicolon
equals
numpad_0
numpad_1
numpad_2
numpad_3
numpad_4
numpad_5
numpad_6
numpad_7
numpad_8
numpad_9
multiply
add
separator
subtract
decimal
divide
f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
command_meta
ZenkakuHankaku

=head1 FUNCTIONS

Functions of Selenium::Remote::WDKeys.

=head2 KEYS

my $keys = KEYS();

A hash reference that contains constant keys. This function is exported by default.

=cut

use strict;
2 changes: 2 additions & 0 deletions lib/Selenium/Waiter.pm
Original file line number Diff line number Diff line change
@@ -118,6 +118,8 @@ sub wait_until (&%) {
return $try_ret if $try_ret;
}

warn 'timeout' if $args->{debug};

# No need to repeat ourselves if we're already debugging.
warn $exception if $exception && !$args->{debug};
return '';
Loading