I try to add cookie to the request in Selenium by JS. Documentation is obvious (http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Options.html#addCookie) but my code snippet doesn't pass any cookie to PHP script(below) on the server.
Client JS code:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
.withCapabilities({'browserName': 'firefox'})
.build();
driver.manage().addCookie("test", "cookie-1");
driver.manage().addCookie("test", "cookie-2").then(function () {
driver.get('http://localhost/cookie.php').then(function () {
driver.manage().addCookie("test", "cookie-3");
driver.manage().getCookie('test').then(function (cookie) {
console.log(cookie.value);
});
setTimeout(function () {
driver.quit();
}, 30000);
});
});
Server PHP code:
<?php
print_r($_COOKIE);
?>