I have a test suite that accesses a URL multiple times and needs to complete a user registration. The individual specs all use the following to clear the session

afterAll(function() { browser.executeScript('window.sessionStorage.clear();'); browser.executeScript('window.localStorage.clear();'); });

The issue is the third time the URL is clicked, it still has the information from the previous registration and thinks that the registration is completed. Is there a limit to clearing sessions and/or is there a better practice to clearing session storage?

  • Be aware that window.localStorage.clear(); clears the data for the current domain only. So the storage will remain untouched if the third URL leads to another domain. If it's the case, you'll have to call get beforehand. It could also be that the storage is rebuilt from the cookies. So make sure to clear them all.
    – Florent B.
    Oct 10, 2017 at 14:07

1 Answer 1


The afterAll() code is executed after all the tests have run at the end of the test-suite. If you want to cleanup after tests you should use afterEach() instead. Protractor uses Jasmine, check the documentation about Setup and TearDowns.

The clear Storage functions do not clear the cookies, only the storage used by the developers. Often session information is stored in cookies instead. You could try to also clear the cookies after each test with browser.manage().deleteAllCookies() or use browser.restart() to start with a fresh session.

Also, see this question.

Your Answer

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

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