Is there a way I can do the equivalent of "incognito mode" with PhantomJS, where all cookies, local storage, etc., is only transient and does not persist across processes?
This would be useful for UI automation as well as some back-end applications.
No, there is no such thing out-of-the-box, but at least there are things you can do for some types of data.
Cache and cookies are by default only visible for one phantom instance, but they can be enabled by setting the files for them from the commandline. So you're good here.
The other problematic features are applicationCache, localStorage and webSQLDatabase determined by running modernizr test suite from phantom.
applicationCache is not really a problem as in most cases only public data is cached. It cannot be cleared after each run.
localStorage can be cleared after each run using localStorage.clear()
(see here), provided you run your tests sequentially. This might not be the case as you probably use multiple processes in parallel to execute faster. No real solution here.
webSQLDatabase still can not be cleared: How to delete a database in Web SQL?
It's sad to say that there are multiple issues with session handling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With