AMA: CodeceptJS support for Safari and IE?

Sahana Asks…

We area VOD startup and we have web app, mobile apps and TV apps. I am writing acceptance tests for web app now and chose codeceptjs framework since we have our website’s front end code in Javascript. We have dockerised the processes and docker images for codeceptjs webdriver IO is availble only for chrome and firefox browsers. How can I handle Safari , Internet Explorer browsers ? Looks like CodeceptJs does not support IE and Safari browsers. Do you have any suggestion?

My Response…

I’ve never personally found the return on investment of getting automated tests running across Internet Explorer and  Safari to be worthwhile as in my experience this took more effort than the bugs it found. So I personally stick to running our full e2e test suite in our most used browser (Chrome) and supplementing this with exploratory testing on all other browsers.

In saying that the reason you won’t be able to use Docker containers for these purposes is that they’re Linux and Internet Explorer requires Microsoft Windows and Safari requires Apple macOS to be able to run. To be able to use these for your existing automated tests you can sign up to a on-demand browser service like SauceLabs and use the remote WebDriver protocol to execute your tests.

Using Watir-WebDriver with Safari (at last!)

Well, it’s official: Watir-WebDriver now 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 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 = :safari

Caveat Emptor

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