Configure Selenium to Control Safari in Private Mode

How do I configure Selenium to control Safari privately? (I am using the Ruby interface).

For context, this is why it's important to run tests in Safari private mode: trying to write to local storage will throw an error in Safari private mode. Therefore, I want automated tests to verify that my code avoids writing to local storage in Private mode. (And perhaps more importantly, will cause future bugs to be brought to the attention of developers

+3


source to share


1 answer


Let's take a look at the definition of Private Browsing: https://support.apple.com/kb/PH19216?locale=en_US

When you use Private Browsing Windows, Safari does not save your browsing history and asks the websites you visit so it doesn't track you.

and here: http://en.wikipedia.org/wiki/Privacy_mode

Privacy mode or "private browsing" or "incognito mode" [1] is a privacy feature in some web browsers to disable browsing history and web cache. This allows a person to browse the web without storing local data that can be retrieved later. Privacy mode will also disable the storage of data in cookies and Flash cookies. This privacy protection only resides on the local computing device as it is still possible to identify frequently visited websites by associating an IP address with a web server.

So this means Selenium is equivalent to enabling private browsing. Every time you run any driver through Selenium, it creates a completely new anonymous profile, you are actually browsing privately. (unless you are using an already created safari profile)



BUT! If you still think that you need to run your safari in incognito mode, you can use the following hack:

you can automate the process of enabling the Private Browsing option using AppleScript. Thus.

  • First, start the Universal Access system setup and enable the "Enable access for assistive devices" option.

  • Launch the Script Editor (in the AppleScript folder inside the Applications folder) and enter the following script:

tell application "Safari"
  activate
end tell

tell application "System Events"
  tell process "Safari"
      tell menu bar 1
          tell menu bar item "Safari"
              tell menu "Safari"
                  click menu item "Private Browsing"
              end tell
          end tell
      end tell
  end tell
end tell

      

Information from here: http://www.macworld.com/article/1139714/enableprivatebrowsing.html

+3


source







All Articles