question about clearing localStorage

299 views
Skip to first unread message

Sebastian Paul

unread,
Mar 25, 2014, 6:19:38 AM3/25/14
to casp...@googlegroups.com


I'm really not sure whats wrong with casper or phantomjs or my thinking but i'll try to explain in pseudocode:


casper.start(http://mywebsite)

casper.echo(localstorage.getitem(accesstoken)) # 23489237493
# i'm logged in
casper.evaluate(localstorage.clear())

#reload
casper.start(http://mywebsite)

#verify i'm logged out by testing for login form

#now do someting to log in (get new accesstoken)

# and log out again by clearing localstorage
casper.evaluate(localstorage.clear())

casper.echo(localstorage.getitem(accesstoken)) # null
# i'm logged out
# i also can verify that i'm logged out by takin screenshots and testing for my login form

#end



thats how i have to run my test, as everytime the test starts the accesstoken is set.


so i think the basic question is: when is the state of localstorage persisted.

Izzet Ozan

unread,
Mar 26, 2014, 6:28:16 AM3/26/14
to casp...@googlegroups.com
Had the same issue today. localStorage.clear() didn't work for me either. 

you need to delete the phantomjs storage manually.

I work on a windows7 computer and deleting the .localstorage-files in \AppData\Local\Ofi Labs\PhantomJS did it for me. PhantomJS stores the sessions and does not reset it when restarting a test.

check this topic:

Hope this hope helpful for you

Sebastian Paul

unread,
Mar 27, 2014, 9:17:03 AM3/27/14
to casp...@googlegroups.com
know about this workaround, but the question remains

why is localstorage on rerun not the last in the last written state, or automatically cleared as in other test frameworks.

Izzet Ozan

unread,
Mar 27, 2014, 9:44:51 AM3/27/14
to casp...@googlegroups.com
have you posted this issue in the phantomjs group? otherwise i will do it. I also need an automated way to delete the localstorage. Even running an explicit JS in Phantomjs for deleting the localstorage does not work. E.g. i am testing a Login to a webapp. but when i rerun the test phantomjs remains logged in. 

i wrote a script like
var page = require('webpage').create();
page.open(url, function (status) {
  localStorage.clear();
  console.log('DOM localStorage cleared');
  phantom.exit();
});

and run this on phantomjs but nothing happens. the localstorage file in \AppData\Local\Ofi Labs\PhantomJS remains unchanged.

Sebastian Paul

unread,
Apr 15, 2014, 10:17:21 AM4/15/14
to casp...@googlegroups.com
No, i haven't
Reply all
Reply to author
Forward
0 new messages