PhantomJS: Reset localStorage after test run
See original GitHub issueBy 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:
- Created 10 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@trkoch Wouldn’t it be advisable to call
localStorage.clear()
inbeforeEach
instead? It makes sense for a test not to assume anything about the previous session.as for
localStorage.clear()
inbeforeEach
what to do in case of karma/node crash on CI environment?