Clear Local storage data for phantomjs

1,155 views
Skip to first unread message

Archana Sharma

unread,
Apr 11, 2014, 4:04:03 AM4/11/14
to phan...@googlegroups.com
I want to run a clear test each time. I tried below js to clear localstorage it is not clearing files

var page = require('webpage').create();
page.open(url, function (status) {
  localStorage.clear();
  phantom.exit();
});

is there any way to do it before each run? 


Darren Cook

unread,
Apr 11, 2014, 4:36:00 AM4/11/14
to phan...@googlegroups.com
> var page = require('webpage').create();
> var url = 'http://localhost:8000';
> page.open(url, function (status) {
> localStorage.clear();
> phantom.exit();
> });

You are in Phantom context there, but I think you need to be in browser
context instead. Does the following code work?

var page = require('webpage').create();
var url = 'http://localhost:8000';
page.open(url, function (status) {
page.evaluate(function(){
localStorage.clear();
});
phantom.exit();
});


Darren

Archana Sharma

unread,
Apr 11, 2014, 4:46:28 AM4/11/14
to phan...@googlegroups.com
Thanks for replay.. i am getting below error when i am running in browser context as suggested in your post :-(

SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

  phantomjs://webpage.evaluate():2
  phantomjs://webpage.evaluate():3
  phantomjs://webpage.evaluate():3
Reply all
Reply to author
Forward
0 new messages