Automation for iOS 9.3.x and above

quality-jam-2017-elise-carmichael-and-corey-pyle-jumpstarting-your-test-automation-12-638

     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.

     The below Machine configuration is mandatory for running Appium automation against an iOS 9.3.x device.

  • Appium: 1.6.4 and above
  • Mac OS: OS X El Capitan 10.11 and Above
  • Xcode Version: 8.0 and Above

Setting up appium-xcuitest-driver

     This is Appiun driver for iOS using XCUITest for back-end. It has the WebDriverAgent which is a WebDriver server implementation for iOS that can be used to remote control iOS devices. It allows you to launch & kill applications, tap & scroll views or confirm view presence on a screen. This makes it a perfect tool for application end-to-end testing or general purpose device automation. It works by linking XCTest framework and calling Apple’s API to execute commands directly on a device. WebDriverAgent is developed and used at Facebook for end-to-end testing and is successfully adopted by Appium.

EXTERNAL DEPENDENCIES

     This package has a lot of external dependencies and we need to ensure that all those dependencies are installed properly to make this work. Below section explains the dependencies and its installations:

libimobiledevice [http://www.libimobiledevice.org/]

Installation  :  > brew install ideviceinstaller

carthage: [https://github.com/Carthage/Carthage]

Installation  :  > brew install carthage

mobiledevice:

Installation: brew install mobiledevice

ios-deploy: [https://github.com/phonegap/ios-deploy]

Installation :   npm install -g ios-deploy

deviceconsole:

Installation : npm install -g deviceconsole

xcpretty: [https://github.com/supermarin/xcpretty]

Installation : gem  install xcpretty

CONFIGURATION FOR REAL DEVICES

The profile can be manually associated with the project (keep in mind that this will have to be done each time the WebDriverAgent is updated).

Once you install the Appium, you will get the path node_modules/appium-xcuitest-driver/WebDriverAgentOpen WebDriverAgent.xcodeproj in Xcode and select your developmentteam for both the WebDriverAgentLib and WebDriverAgentRunner targets. This should also auto select Signing Certificate.

Selecting Signing Certificate for WebDriverAgentLib

1

Select Provisioning Profile for WebDriverAgentRnner [Select a Wildcard Development Provisioning file since this will work for all the bundle ids]

2

     Build WebDriverAgent once to verify all above steps worked. You can just build and save the xcode project [The WebDriverAgentRunner will be installed when you execute your automation script with expected capabilities] OR you can build and install the WebDriverAgentRunner on a device connected to your mac using the below command,

xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=’

Now you are ready to start the automation using XCUITest framework for iOS 9.3.x above devices.

make it perfect !

Appium Desired Capabilities for Android and iOS

Screen-Shot-2016-09-28-at-11.03.39-AM

     Most of the time I observed that people facing the issues at the initial stage of running their automation scripts due to lack of knowledge in the selection of Desired Capabilities based on their Automation platform. Here, I would like to explain important Desired Capabilities for following:

  • Mobile Web Android
  • Mobile Web iOS
  • Mobile Native Android
  • Mobile Native iOS

Mobile Web Android
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Chrome”);

Mobile Web iOS
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI);
capabilities.setCapability(nativeWebTap, true);
capabilities.setCapability(“startIWDP”, true);
capabilities.setCapability(IOSMobileCapabilityType.START_IWDP, true);
capabilities.setCapability(“app”, “path of SAFAILAUNCHERAPPPATH”);
//SAFAILAUNCHERAPPPATH = “/usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/build/SafariLauncher/SafariLauncher.app”
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“realDeviceLogger”, “path of DEVICECONSOLEPATH”);
//DEVICECONSOLEPATH=”/usr/local/lib/node_modules/deviceconsole/deviceconsole”

Mobile Native Android
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(MobileCapabilityType.UDID, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
capabilities.setCapability(MobileCapabilityType.APP, “location of your .APK”);
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, “package name of your Android application”);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, “activity name of your Android application”);

Mobile Native iOS
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(MobileCapabilityType.UDID, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.APP, “location of your .iPA or .APP”);
capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, “bundle ID of your iOS application”);
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“realDeviceLogger”, “path of DEVICECONSOLEPATH”);
//DEVICECONSOLEPATH=”/usr/local/lib/node_modules/deviceconsole/deviceconsole”

     Once you set your Desired Capabilities, next need to instantiate the drivers for Android and iOS in the following way:

For Android
WebDriver driver;
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities)

For iOS
WebDriver driver;
driver = new IOSDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities)

Try to use above mentioned Desired Capabilities in your automation scripts.

make it perfect !

Appium Configuration in Windows and Mac

Configuration of Appium for Android in Windows PC

Step 1: Install latest version of JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html)

Step 2: Set JAVA_HOME

  • Right-click the My Computer icon on your desktop and select Properties.
  • Click Advanced system settings
  • Click the Environment Variables
  • Under User Variables, click New.
  • Enter the variable name as JAVA_HOME
  • Enter the variable value as the installation path for the Java Development Kit as something like “C:\Program Files\Java\jdk1.6.0”
  • Click OK in ‘New User Variable’ dialog box.
  • Under User Variables, select Path in system variable.
  • Click Edit.
  • Scroll to the beginning of the Variable value and insert %JAVA_HOME%\bin;
  • Click OK in ‘Edit User Variable’ dialog box.
  • Click OK in ‘Environment Variables’ dialog box.
  • Click Apply and OKin ‘System Properties’ Windows.
  • If the changes do not take effect restart Windows.

Step 3: Install latest version of eclipse IDE (https://eclipse.org/downloads/)

Step 4: Install TestNG plugin (http://beust.com/eclipse-old/eclipse-6.8.6.20130517_2218/)

Step 5: Install Android SDK(http://developer.android.com/sdk/index.html).

  • Open Eclipse.
  • Select Windows
  • Select
  • Select Android and set the Android SDK
  • Click on Apply and later tap on

Step 6: Set ANDROID_HOME and add tools and platform-tools folders to Path Settings

  • Right-click the My Computer icon on your desktop and select Properties.
  • Click Advanced system settings
  • Click the Environment Variables
  • Under User Variables, click New.
  • Enter the variable name as ANDROID_HOME
  • Enter the variable value as the installation path for the Java Development Kit as something like ” E:\AndroidDev\android-sdk”
  • Click OK in ‘New User Variable’ dialog box.
  • Under User Variables, select Pathsystem variable.
  • Click Edit.
  • Scroll to the beginning of the Variable value and insert E:\AndroidDev\android-sdk\platform-tools; E:\AndroidDev\android-sdk\tools
  • Click OK in ‘Edit User Variable’ dialog box.
  • Click OK in ‘Environment Variables’ dialog box.
  • Click Apply and OK in ‘System Properties’ Windows.
  • If the changes do not take effect restart Windows.

Step 7: Install Appiumfor Windows (use appium-desktop-setup-<latest version>.exe) (https://github.com/appium/appium-desktop/releases).

Configuration of Appium for Android in Mac OS

Step 1: Install latest version of JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html) – download the JDK that specific to Mac OS

Step 2: Set JAVA_HOME

  • Startup Terminal in Mac and enter following commands
  • Type “touch ~/.bash_profile” to create your new file
  • Type “open ~/.bash_profile” to open it in TextEdit
  • Enter “export JAVA_HOME=/<jdk_path>”
  • Type “source ~/.bash_profile” to reload the bash profile to user.
  • Type “echo $JAVA_HOME” to check the path of JDK is set or not.

Step 3: Install latest version of eclipse IDE (https://www.eclipse.org/downloads/?osType=macosx) – download the eclipse that specific to Mac OS

Step 4: Install TestNG plugin (http://beust.com/eclipse-old/eclipse-6.8.6.20130517_2218/)

Step 5: Install Android SDK (http://developer.android.com/sdk/index.html) in Mac specific SDK.

Step 6: Set ANDROID_HOME

  • Startup Terminal in Mac and enter following commands
  • Type “touch ~/.bash_profile” to create your new file
  • Type “open ~/.bash_profile ” to open it in TextEdit
  • Enter “export ANDROID_HOME=/<android sdk_path>”
  • Type “source ~/.bash_profile” to reload the bash profile to user.
  • Type “echo $ANDROID_HOME” to check the path of SDK is set or not.

Step 7: Set tools and platform-tools folders to Path Settings

  • Startup Terminal in Mac and enter following commands
  • Type “touch ~/.bash_profile” to create your new file
  • Type “open ~/.bash_profile ” to open it in TextEdit
  • Type “PATH=<path of platform-tools>: $PATH”
  • Type “PATH=<path of tools>: $PATH”

Step 8: Install Appiumfor Mac. We can install Appium two ways in Mac OS:

  1. By using dmg file (direct download the executable .dmg file and install) (https://github.com/appium/appium-desktop/releases)
  2. Command-line installation method. Open terminal and enter following commands:
    1. brew install node //get node.js
    2. npm install -g appium@<your desired appium version> //get appium
    3. appium //start appium

NOTE: If brew missing in OS X then open http://brew.sh/ and run the following command in terminal:

ruby -e “$(curl –fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

Step 9: Additional tools set up: Genymotion

  • Install Virtualbox in Mac.
  • Install Genymotion in Mac.
  • Open Virtual Device > File menu > Export Appliances > Add virtual emulators by browse (need to download the emulator say Samsung S3 or Samsung S4).
  • Open Genymotion application
  • Add virtual devices/emulators to Genymotion.
  • Run any emulator.
  • Run “adb devices” in terminal to check the list of devices active currently.
  • Open Genymotion and go to Settings> ADB> Set Android SDK path> tap on OK.

Configuration of Appium for iOS in Mac OS

Step 1: Install latest version of JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html) – download the JDK that specific to Mac OS

Step 2: Set JAVA_HOME

  • Startup Terminal in Mac and enter following commands
  • Type “touch ~/.bash_profile” to create your new file
  • Type “open ~/.bash_profile” to open it in TextEdit
  • Enter “export JAVA_HOME=/<jdk_path>”
  • Type “source ~/.bash_profile” to reload the bash profile to user.
  • Type “echo $JAVA_HOME” to check the path of JDK is set or not.

Step 3:Install latest version of eclipse IDE (https://www.eclipse.org/downloads/?osType=macosx) – download the eclipse that specific to Mac OS

Step 4: Install TestNG plugin (http://beust.com/eclipse-old/eclipse-6.8.6.20130517_2218/)

Step 5: Install Xcodelatest version (6.4 or 7.0 and above) (https://developer.apple.com/xcode/download/)

  • Mainly for instruments to start the capturing the screens.
  • Open Xcode: Tap on Xcode menu > Open Developer Tool> Instruments> Start capturing the screen objects.
  • Automation tool in Xcode IDE>UIAutomation using the JavaScript (optional).

Step 6: Install Appiumfor Mac. We can install Appium two ways in Mac OS:

  1. By using dmg file (direct download the executable .dmg file and install) (https://github.com/appium/appium-desktop/releases)
  1. Command-line installation method. Open terminal and enter following commands:
    1. brew install node //get node.js
    2. npm install -g appium@<your desired appium version>  //get appium
    3. appium //start appium

NOTE: If brew missing in OS X then open http://brew.sh/ and run the following command in terminal:

ruby -e “$(curl –fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”