clearing local storage in webview

1,285 views
Skip to first unread message

Patrick Kepler

unread,
Sep 11, 2013, 5:06:09 PM9/11/13
to appium-...@googlegroups.com
Hello,

I'm using the latest version of the appium.app along with the sample webview app to test on the device. I'm having trouble figuring out how to clear the localstorage so I can start from a clean slate. I tried execute_script("localStorage.clear()") in my teardown() method, but that doesn't seem to work. Any ideas?

Thanks.

Jonathan Lipps

unread,
Sep 12, 2013, 5:30:03 AM9/12/13
to Patrick Kepler, appium-...@googlegroups.com
Are you still in webview mode when you call that? I don't know much about localStorage. Is that an object available on window?

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Patrick Kepler

unread,
Sep 12, 2013, 10:28:47 AM9/12/13
to appium-...@googlegroups.com, Patrick Kepler
Yes I was still in webview when calling that method and I think the localStorage object is available on window. Is there any other way to clear cookies, sessions, etc when working with hybrid apps?

Thanks.

Jonathan Lipps

unread,
Sep 12, 2013, 8:30:55 PM9/12/13
to Patrick Kepler, appium-...@googlegroups.com
There are the cookie functions available via the webdriver protocol.

David Luu

unread,
Sep 12, 2013, 8:52:19 PM9/12/13
to appium-...@googlegroups.com, Patrick Kepler
Local storage is separate from cookies, so cookie clearing won't work to clear local storage. However, in recent versions of WebDriver, I believe API methods have been added to directly clear local storage without executing javascript. Check the documentation for the relevant language bindings.

But in terms of javascript, did you try being explicit rather than implicit to clear it as follows in javascript code: "window.localStorage.clear();"? In case there's issues with an implicit call.

David Luu

unread,
Sep 12, 2013, 8:57:58 PM9/12/13
to appium-...@googlegroups.com, Patrick Kepler
Also forgot to mention in my previous post, what I've found in my testing on desktop browsers, is that if what you're testing is on same page/screen as where you've cleared local storage and whatever was "cached" by that was displayed on screen before you cleared the local storage, you then have to "refresh" the page/screen for it to take effect. Don't expect clearing it with javascript only and see a sudden update in the UI (unless it was built that way in the app to auto-update on change of local storage).

And local storage only applies to pages/screens where they're used, it's not necessarily a site-wide/domain-wide thing, so you may have to clear it in the correct location (page/screen) where it's used, not at some other screen/page at the end of the test. It's different from cookies (which are domain based) in that respect. At least that's the case for testing on desktop for our web app.
Reply all
Reply to author
Forward
0 new messages