|
|
@@ -148,7 +148,8 @@ created when you use the find_* methods.
|
|
|
'javascript' - <boolean> - whether javascript should be supported
|
|
|
'auto_close' - <boolean> - whether driver should end session on remote
|
|
|
server on close.
|
|
|
-
|
|
|
+ 'extra_capabilities' - HASH of extra capabilities
|
|
|
+
|
|
|
If no values are provided, then these defaults will be assumed:
|
|
|
'remote_server_addr' => 'localhost'
|
|
|
'port' => '4444'
|
|
|
@@ -165,13 +166,17 @@ created when you use the find_* methods.
|
|
|
my $driver = new Selenium::Remote::Driver;
|
|
|
or
|
|
|
my $driver = new Selenium::Remote::Driver('browser_name' => 'firefox',
|
|
|
- 'platform' => 'MAC')
|
|
|
+ 'platform' => 'MAC');
|
|
|
or
|
|
|
my $driver = new Selenium::Remote::Driver('remote_server_addr' => '10.10.1.1',
|
|
|
'port' => '2222',
|
|
|
auto_close => 0
|
|
|
- )
|
|
|
-
|
|
|
+ );
|
|
|
+ or
|
|
|
+ my $driver = new Selenium::Remote::Driver('browser_name' => 'chrome',
|
|
|
+ 'platform' => 'VISTA',
|
|
|
+ 'extra_capabilities' => {'chrome.switches' => ["--user-data-dir=$ENV{LOCALAPPDATA}\\Google\\Chrome\\User Data"],},
|
|
|
+ );
|
|
|
=cut
|
|
|
|
|
|
sub new {
|
|
|
@@ -208,7 +213,7 @@ sub new {
|
|
|
$self->{remote_conn} =
|
|
|
new Selenium::Remote::RemoteConnection( $self->{remote_server_addr},
|
|
|
$self->{port} );
|
|
|
- $self->new_session();
|
|
|
+ $self->new_session(delete $args{extra_capabilities});
|
|
|
|
|
|
if ( !( defined $self->{session_id} ) ) {
|
|
|
croak "Could not establish a session with the remote server\n";
|
|
|
@@ -242,14 +247,16 @@ sub _execute_command {
|
|
|
# A method that is used by the Driver itself. It'll be called to set the
|
|
|
# desired capabilities on the server.
|
|
|
sub new_session {
|
|
|
- my $self = shift;
|
|
|
+ my ($self, $extra_capabilities) = @_;
|
|
|
+ $extra_capabilities ||= {};
|
|
|
my $args = {
|
|
|
'desiredCapabilities' => {
|
|
|
'browserName' => $self->{browser_name},
|
|
|
'platform' => $self->{platform},
|
|
|
'javascriptEnabled' => $self->{javascript},
|
|
|
'version' => $self->{version},
|
|
|
- }
|
|
|
+ %$extra_capabilities,
|
|
|
+ },
|
|
|
};
|
|
|
my $resp =
|
|
|
$self->{remote_conn}
|
|
|
@@ -263,6 +270,34 @@ sub new_session {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+=head2 mouse_move_to_location
|
|
|
+
|
|
|
+ Description:
|
|
|
+ Move the mouse by an offset of the specificed element. If no
|
|
|
+ element is specified, the move is relative to the current mouse
|
|
|
+ cursor. If an element is provided but no offset, the mouse will be
|
|
|
+ moved to the center of the element. If the element is not visible,
|
|
|
+ it will be scrolled into view.
|
|
|
+
|
|
|
+ Output:
|
|
|
+ STRING -
|
|
|
+
|
|
|
+ Usage:
|
|
|
+ # element - the element to move to. If not specified or is null, the offset is relative to current position of the mouse.
|
|
|
+ # xoffset - X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.
|
|
|
+ # yoffset - Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.
|
|
|
+
|
|
|
+ print $driver->mouse_move_to_location(element => e, xoffset => x, yoffset => y);
|
|
|
+
|
|
|
+=cut
|
|
|
+
|
|
|
+sub mouse_move_to_location {
|
|
|
+ my ($self, %params) = @_;
|
|
|
+ $params{element} = $params{element}{id} if exists $params{element};
|
|
|
+ my $res = { 'command' => 'mouseMoveToLocation' };
|
|
|
+ return $self->_execute_command($res, \%params);
|
|
|
+}
|
|
|
+
|
|
|
=head2 get_capabilities
|
|
|
|
|
|
Description:
|
|
|
@@ -491,6 +526,21 @@ sub refresh {
|
|
|
return $self->_execute_command($res);
|
|
|
}
|
|
|
|
|
|
+=head2 javascript
|
|
|
+
|
|
|
+ Description:
|
|
|
+ returns true if javascript is enabled in the driver.
|
|
|
+
|
|
|
+ Usage:
|
|
|
+ if ($driver->javascript) { ...; }
|
|
|
+
|
|
|
+=cut
|
|
|
+
|
|
|
+sub javascript {
|
|
|
+ my $self = shift;
|
|
|
+ return $self->{javascript} == JSON::true;
|
|
|
+}
|
|
|
+
|
|
|
=head2 execute_script
|
|
|
|
|
|
Description:
|
|
|
@@ -529,11 +579,11 @@ sub execute_script {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- my $params = {'args' => @args};
|
|
|
+ my $params = {'script' => $script, 'args' => [@args]};
|
|
|
my $ret = $self->_execute_command($res, $params);
|
|
|
|
|
|
# replace any ELEMENTS with WebElement
|
|
|
- if (exists $ret->{'cmd_return'}->{'ELEMENT'}) {
|
|
|
+ if (ref($ret) and (ref($ret->{'cmd_return'}) eq 'HASH') and exists $ret->{'cmd_return'}->{'ELEMENT'}) {
|
|
|
$ret->{'cmd_return'} =
|
|
|
new Selenium::Remote::WebElement(
|
|
|
$ret->{'cmd_return'}->{ELEMENT}, $self);
|