What is appium?

As per official website: Appium is an open-source tool for automating native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms. ... Importantly, Appium is "cross-platform": it allows you to write tests against multiple platforms (iOS, Android, Windows), using the same API.

How does it work?

Appium test script written in IDE will interact with the Appium Server which is nothing but the node server with the specified IP address and port number. Node server again passes the request to mobile devices or emulators using the uiautomator or XCUITest as a JSON format. All the UI elements associated with the mobile application can be controlled by using the appium client which is nothing but the derived one of selenium.

Note: Remember using Windows only Android can be automated while in iOS both Android and iOS can be automated.

Installation and setup.

  1. Install Java 8 and setup environment variable.
  2.  Install Maven and setup environment variable.
  3. Install Android studio for android SDK packages.
  4.  Setup android environment variable.
  5. Creating an emulator via android studio.
  6. Enabling Developer mode option in android phone.
  7. Install PDANet (universal driver) to connect with Android devices.
  8. Install Xcode, HomeBrew, Carthage, appium-xcuitest-driver for (Mac only).
  9. Install Appium via npm.
  10. Install Appium via installer.
  11. Install Appium Doctor.

Install Java 8 and setup environment variable.

Download Java 8 from https://www.oracle.com/java/technologies/javase-jdk8-downloads.html and install it.

Next step is to set environment variables. We will set JAVA_HOME and the path variable.

For Mac

For Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile.

Open terminal and type (You must be familiar with vi editor commands).

$ vim .bash_profile

Add below lines

export JAVA_HOME=$(/usr/libexec/java_home)

export PATH=${JAVA_HOME}/bin:$PATH

Save the file

Then run below command.

$ source .bash_profile

To confirm if it is set correctly type

$ echo $JAVA_HOME

It should return below path

/Library/Java/JavaVirtualMachines/1.8.xx.jdk/Contents/Home

Type “java -version” to confirm it.

For Windows:

From windows search bar type advanced system settings.

It will open System Properties window.

Select advance tab and click environment variable.

From system variable, click to new button and enter variable name as JAVA_HOME and value as path to JDK installed.

Next we have to edit the system path variable.

 click on New button, and add this %JAVA_HOME%\bin. Click OK

From command prompt type java -version. The output show java version example:

Install Maven and setup environment variable

Method 1: Via homebrew for mac only.

Run below command to install homebrew.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install maven

brew install maven

Method 2: Manual install

1.         Download maven apache-maven-x.x.x-bin.zip from path https://maven.apache.org/download.cgi and extract to your local  directory.

Setting up Maven environment variable

For Mac

1.         The variable should be updated to bash_profile or ~/.profile.

2.         Open terminal and run below command.

$ vim .bash_profile

export MAVEN_HOME=/Applications/apache-maven-x.x.x

export PATH=$MAVEN_HOME/bin:$PATH

$ source .bash_profile

$ echo $MAVEN_HOME

/Applications/apache-maven-x.x.x

3.         After setting environment variable run mvn -version to confirm if maven is set properly.

For Windows:

From windows search bar type advanced system settings.

It will open System Properties window.

Select advance tab and click environment variable.

From system variable, click to new button and enter variable name as MAVEN_HOME and value as path to the Maven folder present.

Next we have to edit the system path variable.

Click on New button, and add this %MAVEN_HOME%\bin. Click OK

From command prompt type mvn -version. The output show maven

Install Android studio for android SDK packages.

Android Studio Installation and download SDK packages. (Common for both Mac and Windows)

1.         Download Android studio from https://developer.android.com/studio as per your OS and install.

2.         Launch android studio.

3.         Create a dummy project, after Android studio is launched.

4.         Go to Tools  >> SDK manager. In the latest version of Android Studio, the 'SDK Manager' is an icon on the menu. This opens up the SDK manager dialog box.

5.         Select the 'Android SDK' link under 'System Settings' on the left pane, and choose 'SDK Tools' and check the box “Intel x86 Emulator Accelerator” if not checked.

  1.  Uncheck "Hide Obsolete Packages"  option.
  2.  Tick mark "Android SDK Platform -Tools (obsolete)" .
  3.  Click on Apply -> click on OK Button. It will start downloading android sdk to your system.
  4. After installation cross check the path where you are able to see all sdk components.

6.         Note down the Android SDK location path from sdk manager and copy to a notepad.

7.         For ex: /Users/username/Library/Android/sdk

8.         Click OK to download start, it will take some time to download all the components.

9.         Close SDK manager.

Setup android environment variable

For Mac

Just like we set JAVA_HOME, set the Android environment variable.

Open terminal and run below commands

$ vim .bash_profile

export ANDROID_HOME=/Users/username/Library/Android/sdk

export PATH=$ANDROID_HOME/platform-tools:$PATH

export PATH=$ANDROID_HOME/tools:$PATH

Save the file.

$ source .bash_profile

Open terminal and type adb version to verify the environment is set properly.

For Windows

Steps for adding environment in windows are same as above for JAVA_HOME and MAVEN_HOME.

Add ANDROID_HOME and value to sdk location under system variable.

Variable Name: ANDROID_HOME

Variable Value: C:\Users\xxxxx\AppData\Local\Android\Sdk

Then add %ANDROID_HOME%\platform-tools and %ANDROID_HOME%\tools in path variable.

For Mac only

So if we add all environment variables then the file will look like this. Yes. there are some extra variables  added which will come to know as you start automating.

export JAVA_HOME=$(/usr/libexec/java_home)

export PATH=${JAVA_HOME}/bin:$PATH

export ANDROID_HOME=/Users/$(whoami)/Library/Android/sdk

export ANDROID_SDK_ROOT=$ANDROID_HOME

export ANDROID_AVD_HOME=/Users/$(whoami)/.android/avd

export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_SDK_ROOT/emulator:$PATH

export M2_HOME=/Users/$(whoami)/Downloads/Softwares/Maven

export PATH=$PATH:$M2_HOME/bin

Creating an emulator via android studio

  • Open Android studio.
  • Go to Tools >> Android >> AVD Manager.
  • From Virtual configuration window select >> Create a new device.
  • Select the device you want to download. Ex. Pixel
  • Select OS version as per your requirement. Ex.Oreo Android 8.0 with Google APIs.
  • Accept the licence agreement.
  • It will start downloading the image. (Takes time depending on network speed and size).
  • After download start the emulator from avd manager  device list.
  • Enabling Developer mode option in android phone/Emulator

    Go to settings and scroll down to About phone  option.

    Scroll down to Build number and tap multiple times. You can see the toast message “You are now x steps away to being a developer”.

    After tapping 5-7 times when you see “No you are a developer” , which confirms that you have enabled developer mode.

    To confirm go back to the previous page and select System >> Advanced >> Developer option.

    From Developer option scroll down and enable USB debugging, Verify apps over USB option.

    Install PDANet (universal driver) to connect with Android devices

    To interact with devices and system we need a USB driver, usb driver is different with respective to android devices. But we can install one driver which will work across all the android devices.

    1. Go to http://pdanet.co/install/.
    2. Download the installer as per your operating system and install it.

    Install Xcode (For Mac only).

    Open App store and search for xcode then install it.

    Install HomeBrew(For Mac Only)

    Open terminal.

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

    This will install homebrew in your mac machine.

    For more information go through https://brew.sh/

    There is also a dependency, made necessary by Facebook's WebDriverAgent, for the Carthage dependency manager. If you do not have Carthage on your system, it can also be installed with Homebrew

    brew install carthage

    For real devices we can use xcpretty to make Xcode output more reasonable. This can be installed by gem install xcpretty

    More information at : https://www.npmjs.com/package/appium-xcuitest-driver

    For appium-xcuitest-driver installation refer below link.

    https://github.com/appium/appium-xcuitest-driver/blob/HEAD/docs/real-device-config.md

    Appium Setup:

    There are two ways to install such as via npm and installer.

    A) Installing via npm which requires node.js installation.

    Install Node.js

    1.         Download node.js as per your operating system from https://nodejs.org/en/download/.

    2.         After successful installation we have to set the environment variable for Windows OS but for mac it is not needed.

    Open command prompt or terminal and type “npm-v” it returns the version number which confirms that node.js is configured properly.

    Appium Installation

    1.         Open command prompt or terminal in administrator mode and run below command.

    2.         Run npm install -g appium  to install globally, if you want to install a particular version then run npm install -g appium@1.16.0  This will trigger the installation and it will take 5-10 mins depending on your network and RAM size.

    3.         After successful installation run appium command in terminal/command prompt.

    4.         If this returns below result, then Appium is successfully installed to your system.

    B) Install via Appium installer.

    You can download appium installer from appium official website.

    Go to http://appium.io/downloads.html and click to download.

    It will take you to https://github.com/appium/appium-desktop/releases/tag/vx.xx.x

    Select the installer as per your operating system and download.

    Appium-windows-x.xx.x.exe file is for windows and Appium-mac-x.xx.x.dmg file for mac.

    Install it. Then run it will open one window , hit the start button  appium server console.

    Install Appium Doctor

    This tool is used to diagnose and fix common Node, iOS and Android configuration issues before starting Appium.

    To install run below command in terminal

    npm install appium-doctor -g

    To execute, run  appium-doctor command.

    This will give you a report as below, if any configuration is missing please fix them and proceed.