How to setup Selenium, Nightwatch and Appium to work with Safari and iOS 10.3 & Xcode 8.3.3

Lachlan Tweedie
Jul 23, 2017 · 2 min read

I recently got up and running with a local automated testing environment using Selenium and Nightwatch but ran into a few issues while trying to get the Xcode simulator working. I thought I’d write this tutorial to hopefully help anyone running into the same problems.

Prerequisites

Make sure you have the following installed before continuing:

  • Homebrew
  • Node
  • Xcode 8.3.3 (make sure to open at least once and let Xcode make some changes)

Safari

This is the easy bit.

  1. Download the WebDriver named “SafariDriver.safariextz” selenium needs to automate tests on Safari. http://selenium-release.storage.googleapis.com/index.html?path=2.48%2F
  2. Make sure you have the developer menu enabled in Preferences > Advanced > Show develop in menu bar.
  3. Enable automation in by clicking Develop (in menu bar) > Allow Remote Automation.

Done!

Update your nightwatch.json to include a Safari env like this:

And run your tests by passing the new environment:

nightwatch -e safari

Appium, Xcode 8.3.3 & iOS 10.3

Okay, this is a bit tricker but let’s do it.

Install appium-doctor

Appium-doctor tells us what we need installed before we can start using Appium for our tests.

npm install -g appium-doctor

Let’s have a look and see what we need:

appium-doctor -ios

You should see a few things to install, don’t worry though, we’ll get there.

Start off by installing Carthage, a dependency manager for Cocoa.

brew install carthage

Make sure Xcode is pointing towards the developer directory:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

Now we need to install and run a little utility called authorize-ios that pre-authorizes Instruments to run UIAutomation scripts against iOS devices.

npm install -g authorize-ios
sudo authorize-ios

Time to install Appium!

npm -g install appium

At this point if you run appium-doctor everything should be good to go.

Let’s get Appium up and running:

appium &; #start Appium

Here’s an example of the ios env I’m using in my nightwatch.json:

Make sure to have “automationName”: “XCUITest” in your config or Xcode 8.3.3 won’t work!

And run it:

nightwatch -e ios

It might timeout the first time you run it since the simulator takes a while to load.

Done! Feel free to change and test different device names and browsers, or even create a different env for each one.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade