What is Appium Mobile Automation & Installation on Mac OS

Sankar Bala
7 min readMay 17, 2021

--

Content we are going to cover

  1. Introduction
  2. What is Appium?
  3. Installation on Mac OS
  4. How to get appPackage and appActivity
  5. Sample program to run automated UI tests on IOS simulator

Introduction

Mobile automation, as the name suggests, refers to ‘automation’ that is done on mobile devices. Automation is the process whereby one automates testing of an application — in this case a mobile application — which can be a WAP site or an app. This can be done by using tools and helps in reducing the testing time cycle.

What is Appium

Appium automation tool is an open source tool which can be used for automation of different applications like native, wap and hybrid apps.

How it Works on IOS:

For iOS Devices, Appium uses Apple’s native XCUITest API to interact with UI components of Application Under Test. XCUITest is a UI testing framework built on top of Apple’s unit testing framework.

1. Appium client (c/Java/Python/etc) connects with Appium Server and communicates via JSON Wire Protocol.

2. Appium Server then creates an automation session for the client and also checks the desired capabilities of the client and connects with the respective vendor-provided framework like XCUI Test.

3. XCUI Test will then communicate with bootstrap.js which is running in a simulator/emulator/real device for performing client operations.

4. Bootstrap.js will perform the action on our application that is being tested. After the execution of the command, the client sends back the message to the Appium server with the log details of the executed command.

Installation on Mac OS

Step 1: Install Homebrew

Homebrew complements macOS (or your Linux system). Install your RubyGems with gem and their dependencies with brew.

Type following command in terminal to install Homebrew.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Step 2: Install Java 8 (OpenJDK version “1.8.0_291”) its recommended.

  • Download JDK 1.8 from the below link

https://www.oracle.com/in/java/technologies/javase/javase-jdk8-downloads.html#license-lightbox

  • Create Oracle account and install the JDK file
  • Path of the installed file. Go →Go to folder →/Library →Java →Java virtual machine →JDK 1.8 →contents →home
  • For add below ENV variable, open terminal and type vi ~/bash_profile and save it

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH (Press enter).

Step 3:Download and install Android Studio.

  • Please open the below link to download the android studio

https://developer.android.com/studio?gclid=EAIaIQobChMIuvjLrdmj8AIVFZjCCh1OrwSoEAAYASAAEgLXpfD_BwE&gclsrc=aw.ds

Add the below Env path in bash profile and change the username as per yours and click save (wq!) and close the bash.

export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH

export PATH=$ANDROID_HOME/tools:$PATH

Step 4: Installation of node and npm.

  • To install npm type the command brew install node(Press enter)
  • Once you see the below image it is fine and you can close the terminal.
  • Open the terminal again and type the command node -v (Press enter) and you will see the version installed
  • Now enter the command npm –v (Press enter) and you will see the version installed

Step 5:Installation of Appium.

  • Open the terminal and type the command npm install -g appium (Press enter).

Step 6:Install WD required for Appium by using following command.

This library is designed to be implementation of the webdriver protocol in Node, exposing functionality via a number of programming paradigms.

Run following command in terminal to install wd.

$ npm install wd

Step 7:Install Carthage.

Carthage builds your dependencies and provides you with binary frameworks, but you retain full control over your project structure and setup. Carthage does not automatically modify your project files or your build settings.

install Carthage by typing following command in terminal.

$ brew install carthage

Step 8 :Install Webpack.

Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

To install webpack run the below command.

$ npm i -g webpack

Step 9: Install libimobiledevice.

libimobiledevice is A cross-platform FOSS library written in C to communicate with iOS devices natively

https://libimobiledevice.org

To install libimobiledevice run the below command.

$ brew install libimobiledevice

Step 10:Install Xcode from app store.

Create the apple ID and Install Xcode from app store.

Open the App store on MAC.

Search for Xcode.

Click on the Install Button and wait for install to finish.

Open Xcode from applications folder and install required components

Install Command Line Tools if you haven’t already.

Type following command in terminal to install

$ xcode-select --install

Type following command in terminal to set Proper “Xcode” Verison, Required for Build Process.

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Step11: Authorize all ios Devices.

  • Open the terminal run the command npm install -g authorize-ios (Press enter) to authorize for the real devices.

Step 12:Install ios-deploy.

Install and debug iOS apps from the command line. Designed to work on un-jailbroken devices.

https://www.npmjs.com/package/ios-deploy

To install ios-deploy run the below command.

$ npm install -g ios-deploy

Step 13:Install ideviceinstaller.

The ideviceinstaller application allows interacting with the app installation service of an iOS device.

$ brew install ideviceinstaller

Step 14:Install ios-webkit-debug-proxy.

The ios_webkit_debug_proxy (aka iwdp) proxies requests from usbmuxd daemon over a websocket connection, allowing developers to send commands to MobileSafari and UIWebViews on real and simulated iOS devices.

https://github.com/google/ios-webkit-debug-proxy

To install ios-webkit-debug-proxy run the below command.

$ brew install ios-webkit-debug-proxy

Step 15:Install Appium Doctor.

Appium Doctor checks most of the preconditions for Appium to run successfully. Attempts to diagnose and fix common Node, iOS and Android configuration issues before starting Appium.

Run following command in terminal to install appium-doctor.

$ npm install -g appium-doctor

To check the appium health type the command appium-doctor (Press enter). Once done you will see the below image.

Step 16: Installation of Maven.

Apache Maven is a build automation tool for Java projects. Think of Ant, or Make, but much more powerful and easier to use. If you’ve ever had to deal with building a Java project with dependencies or special build requirements then you’ve probably gone through the frustrations that Maven aims to eliminate.

brew install maven

4. How to get appPackage and appActivity

There are many way of getting the apk information . I personally used the first technic and it’s working pretty well. Here is what you should do:

  1. Connect your phone to your computer.
  2. On your phone, open the app you want to know the appPackage and appActivity of.
  3. On your computer, open a shell and type adb shell
  4. On this same shell, type dumpsys window windows | grep -E 'mCurrentFocus' (instead of grep use find for windows os)

Example for Lunching Amazon App and must notice the below statement:

capabilities.setCapability(“appPackage”,”in.amazon.mShop.android.shpping”);
capabilities.setCapability(“appActivity”,“com.amazon.mShop.home.HomeActivity”);.

5. Sample program to Run on Simulator.

Now that we have an IOS app and a UI tests maven project set up, we can start writing simple UI automation tests to run against the IOS app.

1. In IntelliJ/Eclipse, create a file TestIOSSimulator.java under src/main/java directory.

2. In TestIOSSimulator.java file, paste the following code

package com.appium.ios;import java.net.MalformedURLException;import java.net.URL;import java.util.concurrent.TimeUnit;import org.openqa.selenium.remote.DesiredCapabilities;import org.testng.annotations.BeforeSuite;import org.testng.annotations.AfterSuite;import org.testng.annotations.BeforeTest;import org.testng.annotations.Test;import io.appium.java_client.ios.IOSDriver;import io.appium.java_client.ios.IOSElement;import io.appium.java_client.remote.MobileCapabilityType;public class TestIOSSimulator {public static URL url;public static DesiredCapabilities capabilities;public static IOSDriver<IOSElement> driver;@BeforeSuitepublic void setupAppium() throws MalformedURLException {final String URL_STRING = "http://127.0.0.1:4723/wd/hub";url = new URL(URL_STRING);System.out.println("Welcome to app launch");capabilities = new DesiredCapabilities();capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "14.5");capabilities.setCapability(MobileCapabilityType.APP, "/Users/sankarthirugnan/Downloads/TestApp.app");capabilities.setCapability(MobileCapabilityType.NO_RESET, true);capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");capabilities.setCapability("useNewWDA", false);driver = new IOSDriver<IOSElement>(url, capabilities);driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);driver.resetApp();}@AfterSuitepublic void uninstallApp() throws InterruptedException{driver.removeApp("com.bzytan.appiumeveryday");}@Test (enabled=true) public void myFirstTest() throws InterruptedException {driver.resetApp();}}

6. Run automated UI tests on IOS simulator.

With above UI tests written, we are now ready to run our automated UI tests against the IOS app we created on IOS simulator.

1. First, let’s launch the Appium server. Open your terminal and type the following:

$ appium

This will start the Appium server in the foreground, and the server is listening and waiting on any connection from UI tests.

2. Next, we will run the UI tests from eclipse. Right click on the file TestIOSSimulator.java, select Run the project, and it should start running the TestNG tests in the file.

3. In the terminal, you should see Appium server is establishing a connection with the automated UI tests, and as instructed opening up an IOS simulator, installing our IOS app bundle, and executing the automated UI tests against the installed IOS app.

4. Meanwhile, you will see an IOS simulator being opened up and our AppiumUITestsExampleAppIOS app being installed and launched a few times. Our automated UI tests run in eclipse will also finish successfully.

Final Words

Congrats! Folks You have successfully installed and tested ios app on simulator device. i hope it will usefully for your readings too .

--

--