8

I'm trying to use the deleteAllCookies() function from WebDriver from a Protractor test spec.

I've tried:

browser.driver.deleteAllCookies(); // undefined error
browser.driver.options.deleteAllCookies(); // undefined error
browser.manage().deleteAllCookies(); // doesn't seem to be deleting cookies

How do I call/use this function correctly?

5
  • I found this: code.google.com/p/selenium/issues/detail?id=5101 where it seems to be a problem with selenium. The issue is IE specific. Do you have a bit more details about your config, which browsers are you trying to test?
    – Mimo
    Aug 24, 2014 at 9:13
  • I'm testing in Chrome on Ubuntu 14.04 Aug 24, 2014 at 15:05
  • 1
    browser.manage().deleteAllCookies(); works OK for me, Chrome & Firefox, Windows or Ubuntu 14.04 or any Ubuntu I tried. I have a test that clears cookies then browser.navigate().refresh(); to pick the changes since that triggers a login redirect after cookies cleared. Aug 24, 2014 at 20:51
  • If doing the page refresh still doesn't work for you i guess next step is to provide more context for your failing scenario: Protractor version, selenium version, Chrome version, a bit more code on the spec file. Aug 24, 2014 at 20:53
  • browser.manage().deleteAllCookies(); This is not working for me and it was working before. Any suggestion? Oct 21, 2015 at 10:38

2 Answers 2

5

This works for me with protractor 1.5.0, selenium-webdriver: "2.44.0" browser.driver.manage().deleteAllCookies();

2
  • Is it recommended to use it afterEach function() in protractor ?
    – Emna Ayadi
    May 6, 2016 at 16:40
  • 2
    In my opinion, it is a good way to delete cookies in afterEach() in order to prevent cookies from affecting following tests.
    – Miyuki
    May 12, 2016 at 8:18
4

In protractor the way to delete all your cookies is:

ptor.manage().deleteAllCookies();
2
  • 3
    The OP alreadty tried that. browser is the new name (for a few months) of the old ptor variable.
    – JB Nizet
    Aug 24, 2014 at 9:10
  • browser.manage().deleteAllCookies(); does work for me, maybe was fixed/changed in a newer version
    – inolasco
    Apr 21, 2015 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.