Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tod222 committed Aug 22, 2018
2 parents 8d8e386 + 8a346fc commit c368eec
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 52 deletions.
10 changes: 10 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Revision history for Selenium-Remote-Driver

1.29 08-17-2018 TEODESIAN
[New Features]
- Selenium::Edge and Test::Selenium::Edge now exist
- Pass caller argument array as final arg to error_handler callbacks
- Add child() and children() aliases to Selenium::Remote::WebElements
[BUG FIXES]
- Fixed Test::Selenium::* direct usage modules from getting undef method errors when acting on WebElements
- Fixed issue where capabilities could not be passed with Selenium::Firefox
- Make it actually possible for find_element_ok to fail without dying

1.28 06-05-2018 TEODESIAN
[BUG FIXES]
- Fix incorrect documentation of constructor fields.
Expand Down
2 changes: 2 additions & 0 deletions at/sanity.test
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ is(scalar(@{$driver->find_elements('red','class')}),2,"can find multiple element

my $lem = $driver->find_element('body', 'tag_name');
isa_ok($driver->find_child_element($lem, 'red','class'),"Selenium::Remote::WebElement");
isa_ok($lem->child('red','class'),"Selenium::Remote::WebElement");
isa_ok($driver->find_child_element($lem, 'text','name'),"Selenium::Remote::WebElement");
isa_ok($driver->find_child_element($lem, 'Test Link', 'link_text'),"Selenium::Remote::WebElement");
isa_ok($driver->find_child_element($lem, 'Test', 'partial_link_text'),"Selenium::Remote::WebElement");

$lem = $driver->find_element('form','tag_name');
is(scalar(@{$driver->find_child_elements($lem,'./*')}),6,"can find child elements (WD3)");
is(scalar(@{$lem->children('./*')}),6,"can find child elements via children() alias (WD3)");

isa_ok($driver->get_active_element(),"Selenium::Remote::WebElement");

Expand Down
26 changes: 26 additions & 0 deletions at/test-firefox.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use strict;
use warnings;

use Test::Selenium::Firefox;
use Test::More tests => 3;
use Test::Fatal;

my $driver;
is( exception { $driver = Test::Selenium::Firefox->new(
extra_capabilities => {
'moz:firefoxOptions' => {
args => [ '-headless' ],
},
},
); }, undef, "can spawn new Selenium::Firefox");

$driver->get('http://google.com');

TODO: {
local $TODO = "This test must fail";
$driver->click_ok('not_here','css',"click on non-existant element doesn't croak");
};


is( exception { $driver->shutdown_binary; }, undef, "can shutdown binary correctly");

4 changes: 2 additions & 2 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = Selenium-Remote-Driver
version = 1.28
version = 1.29
author = George S. Baugh <[email protected]>
author = Aditya Ivaturi <[email protected]>
author = Daniel Gempesaw <[email protected]>
Expand All @@ -8,7 +8,7 @@ author = Luke Closs <[email protected]>
author = Mark Stosberg <[email protected]>
license = Apache_2_0
copyright_holder = George S. Baugh
copyright_year = 2017
copyright_year = 2018

[GatherDir]
include_dotfiles = 1
Expand Down
109 changes: 61 additions & 48 deletions lib/Selenium/Remote/Driver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -345,49 +345,57 @@ not part of the browser-related desired capabilities.
=back
Output:
Remote Driver object
Selenium::Remote::Driver object
Usage:
my $driver = Selenium::Remote::Driver->new;
or
my $driver = Selenium::Remote::Driver->new('browser_name' => 'firefox',
'platform' => 'MAC');
or (for Firefox 47 or lower on Selenium 3+)
my $driver = Selenium::Remote::Driver->new('browser_name' => 'firefox',
'platform' => 'MAC',
'extra_capabilities' => {
'marionette' => \0,
});
or
my $driver = Selenium::Remote::Driver->new('remote_server_addr' => '10.10.1.1',
'port' => '2222',
'auto_close' => 0);
or
my $driver = Selenium::Remote::Driver->new('browser_name' =>'chrome',
'extra_capabilities' => {
'chromeOptions' => {
'args' => [
'window-size=1260,960',
'incognito'
],
'prefs' => {
'session' => {
'restore_on_startup' => 4,
'urls_to_restore_on_startup' => [
my $driver = Selenium::Remote::Driver->new;
#or
my $driver = Selenium::Remote::Driver->new('browser_name' => 'firefox',
'platform' => 'MAC');
#or (for Firefox 47 or lower on Selenium 3+)
my $driver = Selenium::Remote::Driver->new('browser_name' => 'firefox',
'platform' => 'MAC',
'extra_capabilities' => {
'marionette' => \0,
});
#or
my $driver = Selenium::Remote::Driver->new('remote_server_addr' => '10.10.1.1',
'port' => '2222',
'auto_close' => 0);
#or
my $driver = Selenium::Remote::Driver->new('browser_name' =>'chrome',
'extra_capabilities' => {
'chromeOptions' => {
'args' => [
'window-size=1260,960',
'incognito'
],
'prefs' => {
'session' => {
'restore_on_startup' => 4,
'urls_to_restore_on_startup' => [
'http://www.google.com',
'http://docs.seleniumhq.org'
]},
'first_run_tabs' => [
'http://www.google.com',
'http://docs.seleniumhq.org'
]},
'first_run_tabs' => [
'http://www.google.com',
'http://docs.seleniumhq.org'
]
]
}
}
}
});
or
my $driver = Selenium::Remote::Driver->new('proxy' => {'proxyType' => 'manual', 'httpProxy' => 'myproxy.com:1234'});
or
my $driver = Selenium::Remote::Driver->new('default_finder' => 'css');
});
#or
my $driver = Selenium::Remote::Driver->new('proxy' => {'proxyType' => 'manual', 'httpProxy' => 'myproxy.com:1234'});
#or
my $driver = Selenium::Remote::Driver->new('default_finder' => 'css');
=head3 error_handler
Expand All @@ -411,9 +419,10 @@ already-instantiated driver:
# (we will croak about the exception)
$driver->clear_error_handler;
Your error handler will receive two arguments: the first argument is
Your error handler will receive three arguments: the first argument is
the C<$driver> object itself, and the second argument is the exception
message and stack trace in one multiline string.
message and stack trace in one multiline string. The final argument(s) are the
argument array to the command just executed.
B<N.B.>: If you set your own error handler, you are entirely
responsible for handling webdriver exceptions, _including_ croaking
Expand Down Expand Up @@ -780,6 +789,9 @@ sub DEMOLISH {

# We install an 'around' because we can catch more exceptions this way
# than simply wrapping the explicit croaks in _execute_command.
# @args should be fed to the handler to provide context
# return_value could be assigned from the handler if we want to allow the
# error_handler to handle the errors

around '_execute_command' => sub {
my $orig = shift;
Expand All @@ -792,7 +804,7 @@ around '_execute_command' => sub {
}
catch {
if ($self->has_error_handler) {
$self->error_handler->($self,$_);
$return_value = $self->error_handler->($self,$_,@args);
}
else {
croak $_;
Expand Down Expand Up @@ -955,15 +967,16 @@ sub _request_new_session {

#Delete compatibility layer when using drivers directly
if ($self->isa('Selenium::Firefox')) {
delete $args->{capabilities};
delete $args->{extra_capabilities};
if ( exists $args->{capabilities} && exists $args->{capabilities}->{alwaysMatch} ) {
delete $args->{capabilities}->{alwaysMatch}->{browserName};
delete $args->{capabilities}->{alwaysMatch}->{browserVersion};
delete $args->{capabilities}->{alwaysMatch}->{platformName};
}
}

# geckodriver has not yet implemented the GET /status endpoint
# https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver/status
if (! $self->isa('Selenium::Firefox')) {
$self->remote_conn->check_status();
}
# Get actual status
$self->remote_conn->check_status();

# command => 'newSession' to fool the tests of commands implemented
# TODO: rewrite the testing better, this is so fragile.
my $resource_new_session = {
Expand Down
16 changes: 16 additions & 0 deletions lib/Selenium/Remote/WebElement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ has 'driver' => (

=head1 FUNCTIONS
=head2 child(selector, method)
=head2 children(selector, method)
Alias to Selenium::Remote::Driver::find_child_element and find_child_elements, respectively.
=cut

sub child {
return $_[0]->{driver}->find_child_element(@_);
}

sub children {
return $_[0]->{driver}->find_child_elements(@_);
}

=head2 click
Description:
Expand Down
5 changes: 5 additions & 0 deletions lib/Test/Selenium/Chrome.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package Test::Selenium::Chrome;
use Moo;
extends 'Selenium::Chrome', 'Test::Selenium::Remote::Driver';

has 'webelement_class' => (
is => 'rw',
default => sub {'Test::Selenium::Remote::WebElement'},
);

1;

__END__
Expand Down
28 changes: 28 additions & 0 deletions lib/Test/Selenium/Edge.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package Test::Selenium::Edge;

use Moo;
extends 'Selenium::Edge', 'Test::Selenium::Remote::Driver';

has 'webelement_class' => (
is => 'rw',
default => sub {'Test::Selenium::Remote::WebElement'},
);

1;

__END__
=head1 NAME
Test::Selenium::Edge
=head1 SYNOPSIS
my $test_driver = Test::Selenium::Edge->new;
$test_driver->get_ok('https://duckduckgo.com', "MS Edge can load page");
$test_driver->quit();
=head1 DESCRIPTION
A subclass of L<Selenium::Edge> which provides useful testing functions. Please see L<Selenium::Edge> and L<Test::Selenium::Remote::Driver> for usage information.
5 changes: 5 additions & 0 deletions lib/Test/Selenium/Firefox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package Test::Selenium::Firefox;
use Moo;
extends 'Selenium::Firefox', 'Test::Selenium::Remote::Driver';

has 'webelement_class' => (
is => 'rw',
default => sub {'Test::Selenium::Remote::WebElement'},
);

1;

__END__
Expand Down
5 changes: 5 additions & 0 deletions lib/Test/Selenium/InternetExplorer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package Test::Selenium::InternetExplorer;
use Moo;
extends 'Selenium::InternetExplorer', 'Test::Selenium::Remote::Driver';

has 'webelement_class' => (
is => 'rw',
default => sub {'Test::Selenium::Remote::WebElement'},
);

1;

__END__
Expand Down
5 changes: 5 additions & 0 deletions lib/Test/Selenium/PhantomJS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package Test::Selenium::PhantomJS;
use Moo;
extends 'Selenium::PhantomJS', 'Test::Selenium::Remote::Driver';

has 'webelement_class' => (
is => 'rw',
default => sub {'Test::Selenium::Remote::WebElement'},
);

1;

__END__
Expand Down
11 changes: 9 additions & 2 deletions lib/Test/Selenium/Remote/Driver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,15 @@ sub _find_element_with_action {
$desc = $method;
$desc .= "'" . join( " ", ( $params // '' ) ) . "'";
}
return $self->find_element( $locator, $locator_strategy )
->$method( $params, $desc );
my $element;
eval {
$element = $self->find_element( $locator, $locator_strategy );
};
if ($@) {
print "# Error: $@\n";
return 0;
}
return $element->$method( $params, $desc );
}

=head2 $twd->type_element_ok($search_target [,$locator], $keys, [, $desc ]);
Expand Down

0 comments on commit c368eec

Please sign in to comment.