Tamer Hussien
Tamer Hussien

Reputation: 837

WebDriverError: unable to set cookie javascript

I'm trying to set a cookie in Protractor and its not allowing me.

Here is the error:

    WebDriverError: unable to set cookie
  (Session info: chrome=63.0.3239.132)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64)
    at WebDriverError (e:\node_modules\selenium-webdriver\lib\error.js:27:5)
    at Object.checkLegacyResponse (e:\node_modules\selenium-webdriver\lib\error.js:505:15)
    at parseHttpResponse (e:\node_modules\selenium-webdriver\lib\http.js:509:13)
    at doSend.then.response (e:\node_modules\selenium-webdriver\lib\http.js:440:13)
    at process._tickCallback (internal/process/next_tick.js:109:7)

Here is the test code that responsible for setting the cookies

beforeEach(function() {
        //Enable Angular synchonization
        protractor_1.browser.waitForAngularEnabled(true);
        //Disable animations
        protractor_1.browser.manage().addCookie({ name: 'disableAnimations', value: 'true' }, '/', '127.0.0.1');
    });

Why is my test code not able to set the cookie?

Upvotes: 4

Views: 3302

Answers (1)

Xotabu4
Xotabu4

Reputation: 3091

If thats the full code - i can only suggest that you must first open the page for which domain you want to add cookies, like:

beforeEach(function () {
    protractor_1.browser.waitForAngularEnabled(true);
    browser.get('http://127.0.0.1:8080') // set your url here
    //Disable animations
    protractor_1.browser.manage().addCookie({
        name: 'disableAnimations',
        value: 'true'
    }, '/', '127.0.0.1');
});

Selenium can only set cookies for already opened domain page

Upvotes: 7

Related Questions