Selenium-Remote-Driver
view release on metacpan or search on metacpan
t/01-webdriver3.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Deep;
use Test::Fatal;
use Scalar::Util qw{looks_like_number};
use Selenium::Remote::Driver;
use Selenium::Firefox::Profile;
use Selenium::Remote::Spec;
#So we only modify _request_new_session to get webd3 working.
#As such, we should only test that.
NEWSESS: {
#TODO cover case where ISA Selenium::Firefox
my $self = bless({ is_wd3 => 1 },"Selenium::Remote::Driver");
my $profile = Selenium::Firefox::Profile->new();
$profile->set_preference(
'browser.startup.homepage' => 'http://www.google.com',
);
my $args = {
desiredCapabilities => {
browserName => 'firefox',
version => 666,
platform => 'ANY',
javascript => 1,
acceptSslCerts => 1,
firefox_profile => $profile,
pageLoadStrategy => 'none',
proxy => {
proxyType => 'direct',
proxyAutoconfigUrl => 'http://localhost',
ftpProxy => 'localhost:1234',
httpProxy => 'localhost:1234',
sslProxy => 'localhost:1234',
socksProxy => 'localhost:1234',
socksVersion => 2,
noProxy => ['http://localhost'],
},
extra_capabilities => { #TODO these need to be translated as moz:firefoxOptions => {} automatically, and then to be put in the main hash
binary => '/usr/bin/firefox',
args => ['-profile', '~/.mozilla/firefox/vbdgri9o.default'], #gotta check this gets overridden
profile => 'some Base64 string of a zip file. I should really make this a feature',
log => 'trace', #trace|debug|config|info|warn|error|fatal
prefs => {}, #TODO check that this is auto-set above by the Selenium::Firefox::Profile stuff
webdriverClick => 0, #This option is OP, *must* be set to false 24/7
},
},
};
no warnings qw{redefine once};
local *Selenium::Remote::RemoteConnection::request = sub {return { sessionId => 'zippy', cmd_status => 'OK', cmd_return => {capabilities => 'eee'} }};
local *File::Temp::Dir::dirname = sub { return '/tmp/zippy' };
use warnings;
my ($args_modified,undef) = $self->_request_new_session($args);
my $expected = {
'alwaysMatch' => {
'browserVersion' => 666,
'moz:firefoxOptions' => {
'args' => [
'-profile',
'/tmp/zippy'
],
'binary' => '/usr/bin/firefox',
'log' => 'trace',
'prefs' => {},
'profile' => 'some Base64 string of a zip file. I should really make this a feature',
'webdriverClick' => 0
},
'platformName' => 'ANY',
'proxy' => {
'ftpProxy' => 'localhost:1234',
'httpProxy' => 'localhost:1234',
'noProxy' => [
'http://localhost'
],
'proxyAutoconfigUrl' => 'http://localhost',
'proxyType' => 'direct',
'socksProxy' => 'localhost:1234',
'socksVersion' => 2,
'sslProxy' => 'localhost:1234'
},
'browserName' => 'firefox',
'pageLoadStrategy' => 'none',
acceptInsecureCerts => 1,
}
};
is($self->{capabilities},'eee',"Caps set correctly in wd3 mode");
is_deeply($args_modified->{capabilities},$expected,"Desired capabilities correctly translated to Firefox (WD3)");
#$expected->{alwaysMatch}->{'goog:chromeOptions'} = $expected->{alwaysMatch}->{'moz:firefoxOptions'};
$expected->{alwaysMatch}->{'moz:firefoxOptions'} = {};
#$expected->{alwaysMatch}->{'goog:chromeOptions'}->{args} = ['-profile', '~/.mozilla/firefox/vbdgri9o.default'];
$expected->{alwaysMatch}->{browserName} = 'chrome';
$args->{desiredCapabilities}->{browserName} = 'chrome';
($args_modified,undef) = $self->_request_new_session($args);
is_deeply($args_modified->{capabilities},$expected,"Desired capabilities correctly translated to Krom (WD3)");
}
EXECOMMAND: {
#_execute_command with payload 'hitting all the right buttons'
#also check that fallback works w/ the right special missing word
#also check capability shortcut
my $self = bless({ is_wd3 => 1, capabilities => 'wakka wakka', browser_name => 'firefox' },"Selenium::Remote::Driver");
no warnings qw{redefine once};
local *Selenium::Remote::RemoteConnection::request = sub {return { sessionId => 'zippy', cmd_status => 'OK' }};
local *Selenium::Remote::Spec::get_params = sub { my ($self,$ret) = @_; $ret->{v3} = 1; return $ret; };
local *Selenium::Remote::Commands::get_params = sub { die 'whee' };
local *Selenium::Remote::Spec::parse_response = sub { my ($self,undef,$ret) = @_; $ret->{rv3} = 1; return $ret; };
local *Selenium::Remote::Commands::parse_response = sub { die 'zippy' };
use warnings;
my ($input,$params) = ({ command => 'zippy'},{ ms => 1, type=> 1, text => 1, value => 1, using => 1});
my $ret = $self->_execute_command($input,$params);
is($ret->{rv3},1,"v3 code walked in _execute_command on happy path");
$input->{command} = 'getCapabilities';
$ret = $self->_execute_command($input,$params);
is($ret,'wakka wakka',"v3 code walked in _execute_command on getCapabilities path");
( run in 0.502 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )