question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PhantomJS: Reset localStorage after test run

See original GitHub issue

By default PhantomJS keeps localStorage settings across sessions. While this is equivalent to a real browser, it can be problematic in a test setup. If a test leaves traces in the localStorage (say, a user is logged in) seemingly random failures can happen (false negatives and positives).

From my observations I guess Chrome and other real browsers are reset across test runs (i.e. they get a new preference directory). I suggest to treat Phantom similarly.

On Mac OS, Phantom writes its localStorage settings by default to /Users/<User>/Library/Application Support/Ofi Labs/PhantomJS. This can be changed with the --local-storage-path flag.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
guioconnorcommented, Feb 16, 2016

@trkoch Wouldn’t it be advisable to call localStorage.clear() in beforeEach instead? It makes sense for a test not to assume anything about the previous session.

0reactions
ciekawycommented, Feb 25, 2016

as for localStorage.clear() in beforeEach what to do in case of karma/node crash on CI environment?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to clean localstorage and sessionstorage on phantom?
localStorage.clear() to clear local storage in PhantomJS. ... Before you run each test, check for the existence of the file *.localstorage ...
Read more >
Clear Local storage data for phantomjs - Google Groups
I want to run a clear test each time. I tried below js to clear localstorage it is not clearing files. var page...
Read more >
Command Line Interface - PhantomJS
Supported command-line options are: --help or -h lists all possible command-line options. Halts immediately, will not run a script passed as argument ...
Read more >
TIL: Mocking localStorage and sessionStorage in Angular Unit ...
In this Service's unit tests, we don't want it to use the real localStorage because our tests should be able to run independently...
Read more >
How to Clear Local Storage JavaScript - W3docs
There is a simple way of o resetting a browser's localStorage using its clear() method. Just invoke the clear() of the Storage interface...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found