Safari

Watir-WebDriver supports Safari thanks to the release of SafariDriver.

The downside is the set up is quite lengthy at the moment as it requires a Safari extension (version 5+) and until someone publishes the extension to the online gallery, you’ll have to build it yourself.

Steps to build the extension

  1. First, create and install a Safari extension certificate at Apple. You’ll need to sign up for a (free) Safari developer account, and download your certificate locally.
  2. Now, you’ll need to build the extension. First, you’ll need to check out the selenium source code to do so:
    svn co http://selenium.googlecode.com/svn/trunk selenium
  3. Then change into this directory and build the extension
    cd selenium
    ./go safari
  4. Finally, install your extension:
    1. Launch Safari
    2. Ensure develop menu is shown by setting it in Advanced Preferences 
    3. Open the Extension Builder (Develop > Show Extension Builder)
    4. Add your new extension from: $SELENIUM_CHECKOUT_LOCATION/build/javascript/safari-driver/SafariDriver.safariextension

Using Safari with Watir-WebDriver

It’s exactly the same as any other browser:

require 'watir-webdriver'
b = Watir::Browser.new :safari

Caveat Emptor

  • browser.execute_script is a little flaky
  • Can’t use local html files as extensions don’t load
  • Can’t perform browser file uploads at present
  • Not sure how to configure browser options programatically like user agent strings

Enjoy!