-
Notifications
You must be signed in to change notification settings - Fork 2
Setup ‐ iOS
This page contains information for setting up local iOS environment for running automated tests against iOS Simulators. You will find information for setting up latest appium / iOS Simulators.
- You need to have a MAC machine and existing app store account. For app store account - you can create it on the fly it is free and you don`t need to link it with any credit cards.
- Download and install latest jdk for MAC - Download Link
- Download latest Xcode Developer Tools - just open App Store application and search for xcode. You can get the latest one (for now it is 8.2.1)
- Install Xcode once it is downloaded (follow the basic approach Next / Next / Finish :) )
- Once Xcode is installed you will have latest iOS Simulators on the machine (in our case 10.2). If you want to have iOS Simulators with other versions then you can do the following -> Open Xcode and from the menu -> Xcode -> Preferences -> Components -> click on the version you want ( you will see a list with all simulator versions 10.1 / 10.0 / 9.3 / 9.2 / 9.1 / etc)
- Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Install node
brew install node
- Verify node and npm are installed correctly
node -v
npm -v
Installing appium is really easy. You can find few examples below which could be useful in different situations
- Installing latest appium version in npm
npm install -g appium
- Install specific appium version from npm
npm install -g appium@1.6.3
Once appium is installed we have to install other dependencies which are needed in order to run the tests:
- Install carthage
brew install carthage
- Install authorize-ios
npm install -g authorize-ios
- Execute authorize-ios as sudo user
sudo authorize-ios
- Install appium-doctor
npm install -g appium-doctor
- Execute appium-doctor
appium-doctor --ios
If you follow the steps above once appium-doctor is executed it will say that command line tools for Xcode are not installed. If you click Yes as an option appium-doctor will start downloading them and you can follow the wizard to install them. It is recommended once you install them to run appium-doctor one more time. Then you will see that all actions / dependencies are done and you are ready to proceed with running the tests on your machine.
In order to start appium you can run the command below. It will start appium and it will listen for request on http://0.0.0.0:4723/wd/hub url. Basically it will start appium with all default options / configs.
appium
As you can see from the examples above the minimum capabilities that you need to provide are:
- PLATFORM_NAME - it should be iOS
- PLATFORM_VERSION - this is the iOS Simulator version that you want to execute. So if you have downloaded several iOS Simulator version then you can put any of the values here in order to start them. For example 10.2 / 10.1 / 9.2 / etc
- DEVICE_NAME - this is the name of the device that you want to start - you can go to Xcode -> Open Developer Tool -> Simulator and it will run default iOS Simulator. After that you can click on the Simulator and from the menus to see all names - Hardware -> Device -> iOS 10.2 -> ... List with names
- AUTOMATION_NAME - for all tests using iOS Simulator Version >= 9.3 you should set this to XCUITest. Below you can see why it is needed
For iOS automation, Appium relies on system frameworks provided by Apple. For iOS 9.2 and below, Apple's only automation technology was called UIAutomation, and it ran in the context of a process called "Instruments". As of iOS 10, Apple has completely removed the UIAutomation instrument, thus making it impossible for Appium to allow testing in the way it used to. Fortunately, Apple introduced a new automation technology, called XCUITest, beginning with iOS 9.3. For iOS 10 and up, this will be the only supported automation framework from Apple.
Appium has built in support for XCUITest beginning with Appium 1.6. For the most part, the capabilities of XCUITest match those of UIAutomation, and so the Appium team was able to ensure that test behavior will stay the same. This is one of the great things about using Appium! Even with Apple completely changing the technology your tests are using, your scripts can stay mostly the same! That being said, there are some differences you'll need to be aware of which might require modification of your test scripts if you want to run them under our XCUITest automation backend. This document will help you with those differences.
- BROWSER_NAME - it should be safari
- launchTimeout - in seconds for how much time the Simulator should be ready.
Below you can see two examples with iPhone / iPad Simulators.
private DesiredCapabilities getAppiumiPhoneCapabilities(){
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.2");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 7");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "safari");
capabilities.setCapability("launchTimeout", 180);
return capabilities;
}
private DesiredCapabilities getAppiumiPhoneCapabilities(){
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.2");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPad Air 2");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "safari");
capabilities.setCapability("launchTimeout", 180);
return capabilities;
}
If you want to run a test you can do this:
public void appiumiOSExample() throws Exception {
DesiredCapabilities capabilities = getAppiumiPhoneCapabilities();
WebDriver webDriver = new IOSDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
webDriver.get("http://detectmybrowser.com/");
}
WIKI
How To - Local