How to setup Selenium, Nightwatch and Appium to work with Safari and iOS 10.3 & Xcode 8.3.3
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.
- 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
- Make sure you have the developer menu enabled in Preferences > Advanced > Show develop in menu bar.
- 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 safariAppium, 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-doctorLet’s have a look and see what we need:
appium-doctor -iosYou 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 carthageMake sure Xcode is pointing towards the developer directory:
sudo xcode-select --switch /Applications/Xcode.app/Contents/DeveloperNow 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-iosTime to install Appium!
npm -g install appiumAt this point if you run appium-doctor everything should be good to go.
Let’s get Appium up and running:
appium &; #start AppiumHere’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 iosIt 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.
