How to automatically test local session storage in Safari?

374 views
Skip to first unread message

Maciej Gawinecki

unread,
Nov 22, 2016, 7:01:01 AM11/22/16
to Selenium Users
Safari Web Driver opens Safari browser instances in private mode.

Safari in private mode does not allow JavaScript to save in local session storage [1].

How do I automate Selenium tests for Safari for the application that uses local session storage?

Regards,
Maciej

  [1]: http://stackoverflow.com/questions/18860098/on-a-browser-sessionstorage-in-safaris-private-browsing-does-not-work-the-same

David

unread,
Nov 22, 2016, 12:19:52 PM11/22/16
to Selenium Users
Well, the SO link you refer to, for it's accepted answer, in the comments section, there is a link to a workaround. You can try that, it may not be perfect and can't likely be used to test "persistent/persisted" session storage (I'm assuming across pages or navigation perhaps), but kind of works, at least within the same "page".

Basically load/inject that javascript code snippet [1] with Selenium's javascript executor after page load, then you should be able to use/test session storage on that page. But you'll have to do that after each page load on any page you want to test, unless you have your developers automatically include/load that javascript as part of the website/application in "test" mode, then it would work for every page without you injecting it. With you manually injecting, it will not capture/test session storage use prior to page load completion. There may be other solutions for faking or working around having no session storage as well if you search online, besides [1].

Maciej Gawinecki

unread,
Nov 23, 2016, 5:47:35 AM11/23/16
to Selenium Users
David,

Thank you, but this workaround actually mocks local storage.

By mocking local storage we actually are not testing local storage.

It looks more like a limitation of Safari than of Selenium. Seems more like a question to Safari team, right?

Regards,
Maciej

Maciej Gawinecki

unread,
Nov 23, 2016, 6:51:08 AM11/23/16
to Selenium Users
Or perhaps Selenium should not run Safari in private mode?

Maciej

David

unread,
Nov 23, 2016, 12:27:00 PM11/23/16
to Selenium Users
If we're talking the latest SafariDriver, then blame Apple, they develop that (not Selenium WebDriver core team). If we're talking the deprecated SafariDriver extension for older Safari versions, also blame Apple, their design decisions around how extensions work and security of the browser made it hard to automate Safari via WebDriver protocol.

The new SafariDriver officially from Apple is much improved, but from what you say, sounds like there is still improvements to be made. Apple perhaps made their browser a tad too secure in that respect, even for test automation :(

I suggest you ask about this on Apple's Safari forum, although perhaps better to just file a bug (or rather feature request) to Apple about this. But first, check if one already exists on https://openradar.appspot.com/page/1. If not, file your bug then file a copy of it on OpenRadar. It's sad Apple does not offer a publicly viewable bug tracking system. You only see bugs you file, you can't see related bugs if say yours was marked a duplicate. 
Reply all
Reply to author
Forward
0 new messages