Issue
Recently I upgraded to a recent version of chromium[1] and now third party cookies are disabled by default. Now one of my tests fails against selenium[2] using chromedriver[3] because it relies on a third party cookie (Facebook).
The setting that I want to change seems to reside in the file /path/to/profile/Default/Preferences
in JSON as something like:
{
...
"profile" : {
...
"block_third_party_cookies": false,
...
}
...
}
I want to configure chromium such that this setting is false in my selenium session.
Things I have tried that failed:
I am using the perl driver library that allows me to pass some options that will be used during session creation.
I tried to change the profile directory and the following appeared in my selenium server output:
14:33:53.312 INFO - Executing: [new session: {platform=ANY, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, proxy={proxyType=direct}, chrome.switches=--user-data-dir=/path/to/profile/..., version=}] at URL: /session)
I would think that this approach should work but that I just need to know the correct parameter name(s).
Changing the setting in
/etc/chromium/master_preferences
[1] Chromium version 31.0.1650.63 Debian
[2] Selenium standalone version 2.25.0
[3] Chromedriver version 2.6.232917
Solution
The solution I found uses the chromeOptions.args capability to set a profile. I created a profile template with the correct setting. I used this profile as a template.
In the profile template directory there is a single file named Default/Preferences
with the contents:
{
"profile": {
"block_third_party_cookies": false
}
}
The perl test file looks something like:
use Selenium::Remote::Driver;
use File::Temp 'tempdir';
my $template_dir = '/path/to/template/dir/';
my $dirname = tempdir(
'chrome_user_data_XXXXXX',
DIR => '/tmp',
CLEANUP => 1,
);
system(qq|cp -a $template_dir/* $dirname|) == 0
or die("Could not copy $template_dir/* to $dirname");
my $driver = Selenium::Remote::Driver->new(
browser_name => 'chrome',
extra_capabilities => {
args => ["user-data-dir=$dirname"],
},
);
Answered By - Marius Olsthoorn