I'm writing some tests for a website who has a cookie consent redirection thta of course disappears once you click it away, bringing back to the original site.
what I can't do is to set the cookie basically.
My goal is, once cookies are there, I won't be redirected t the cookie consent page, but I will stay directly on the website itself.
I read something in the documentation of Galen and Selenium as well, but still I can't find any working solution.
This is my current code, you can see some cookie related functions.
load("../import/devices.js");
load("../import/sites.js");
forAll(devices, function (option) {
var site = sites[System.getProperty("project")];
test("Check menu on ${deviceName}", function () {
var browserStack = new createGridDriver("http://" + System.getProperty("browserstack.username") + ":" + System.getProperty("browserstack.key") + "@hub.browserstack.com/wd/hub", {
desiredCapabilities: {
browser: option.browser,
browser_version: option.browser_version,
os: option.os,
os_version: option.os_version,
browserName: option.browserName,
platform: option.platform,
device: option.device,
emulator: option.emulator,
"browserstack.debug": "true"
}
});
// ATTEMPT 1 TO SET COOKIES
browserStack.manage().addCookie("cookie-for-consent", "true", "domain", "/");
var HomePage = $page("Home page", {
navigation: "div.header__navigation",
load: function () {
this.open(site.url);
return this.waitForIt();
}
});
logged("Check not found page title", function () {
// ATTEMPT 2 TO SET COOKIES
cookie(browserStack, "cookie-for-consent=true; domain=mydomani.nl; path=/");
var homePage = new HomePage(browserStack).load();
browserStack.quit();
});
});
});
Attempt 1 has this error =>
org.mozilla.javascript.EvaluatorException: Can't find method org.openqa.selenium.WebDriver$Options.addCookie(string,string).
Attempt 2 has this error =>
org.mozilla.javascript.WrappedException: Wrapped org.openqa.selenium.WebDriverException: <unknown>: Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs.
(Session info: chrome=42.0.2311.135)
(Driver info: chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 33 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: '185-129-70-56', ip: '185.129.70.56', os.name: 'windows', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Windows\proxy\scoped_dir3980_19300}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=42.0.2311.135, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 86e4680decaadaf6e9e211cabf502100
Command duration or timeout: 327 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'silversonicaxel.ws2.tem.nl', ip: '10.41.1.104', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Windows\proxy\scoped_dir3980_19300}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=42.0.2311.135, platform=WINDOWS, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, webdriver.remote.sessionid=59d3ea61b454ff0ca8dd9113247684b0a95e9b98, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 59d3ea61b454ff0ca8dd9113247684b0a95e9b98 (<cmd>#184)
So, question how to fix the issue?
Thanks in advance