Skip to main content

Android & iOS Mobile Apps Testing - Part 1

Saurabh Dhariwal

Saurabh Dhariwal

3 Minutes
Beginner's Guide to Appium

Introduction to Appium

Appium is an open-source tool for automating native, mobile web, and hybrid applications on iOS devices, Android devices, and Windows desktop platforms. It also supports automation tests on physical devices as well as an emulator or simulator both.

 

Native apps are those kinds of applications that are written using the iOS, Android, or Windows SDKs.

 

Mobile web apps can be accessed using a mobile browser (Appium supports Safari on iOS devices and Chrome or the built-in 'Browser' app on Android devices).

 

Hybrid apps use a wrapper around a "webview" -- a native control that enables interaction with web content.

 

It offers cross-platform applications testing, i.e. one single API works for Android and iOS platform test scripts.

 

It has NO dependency on Mobile device OS. APPIUM has a framework or wrapper that translates Selenium Webdriver commands into UIAutomation (iOS) or UIAutomator (Android) commands depending on the device type, not OS type.

 

Appium supports multiple programming languages such as Ruby, Python, JAVA, JavaScript, C# and PHP.

How does Appium work?

How does Appium work?

 

  • Appium Server is written in Node.js.
  • It uses a client-server architecture.
  • The test script can be written in multiple programming languages such as Ruby, Python, JAVA, JavaScript, C# and PHP.
  • Client machines communicate with the server via the JSON Wire protocol to begin an automation test session by sending a request to the appium server.
  • The Appium Server invokes the iOS or Android drivers by creating a new test automation session.
  • The Appium Server ties with the corresponding native testing frameworks to link with the bootstrap.jar/bootstrap.js running on the mobile devices to perform operations on the device.
  • Through Appium, it is feasible for testers/developers to use the same test script to test iOS and Android devices.
  • However, the problematic point here is to differentiate between iOS and Android devices’ test automation requests. Appium overcomes this by providing the desired capabilities. When a request session is created, the key-value pairs such as deviceName, platformName, appPackage, appActivity etc., have been mentioned. Based on those mentioned key-value pairs, the Appium Server directs the client requests to the corresponding test frameworks.

Appium on Android Devices

  • Client machines communicate with the server via the JSON Wire protocol to begin an automation test session by sending a request to the appium server.
  • The server checks the desired capabilities. For Android platform testing, the server looks out for the UiAutomator2 - native testing automation framework in Android.
  • UiAutomator2 communicates with the bootstrap.jar running on the device as a TCP server. It works on emulators, simulators and real devices as well.
  • Bootstrap.jar receives the requests and runs the tests on Android devices. It hands over the test log details to the UiAutomator2 and passes it to the Appium Server. Bootstrap.jar forwards that information to the client.

Appium on iOS Devices

  • Client machines communicate with the server via the JSON Wire protocol to begin an automation test session by sending a request to the appium server.
  • The server checks the desired capabilities. For iOS platform testing, the server looks out for the XCUITest - native testing automation framework in iOS, which comes with Apple XCode.
  • XCUITest communicates with the bootstrap.js running on the device as a TCP server. It works on emulators, simulators and real devices as well.
  • Bootstrap.js receives the requests and runs the tests on iOS devices. It hands over the test log details to the XCUITest and passes it to the Appium Server. Bootstrap.js forwards that information to the client.

Getting started

Installing Appium in Mac

 

  • Installation via NPM

 

Step 1: Install Node.js and check if it is installed using the following commands:

brew install node
node -v
npm -v

 

Step 2: Install appium and check if it is installed using the following commands:

npm install -g appium
appium -v

 

Step 3: Install appium client and start appium

npm install wd     
appium

 

Also, install an appium doctor using

npm install appium-doctor -g

 

For uninstalling appium

uninstall -g appium

 

  • Installation via Desktop App Download

 

>> Download and install Appium desktop from http://appium.io/

 

https://experitest.com/appium-blog/what-is-appium-server/#Appium-Installation

Connect real Android device on Mac

Pre-requisites

 

  1. Java installed on the system
  2. JAVA_HOME is set in environment variables, and to check, use command java -version
  3. An android mobile device
  4. To connect the mobile device to the computer system, need a cable

 

Step 1: Download Android SDK

 

Way 1: Download from https://developer.android.com/studio​

Way 2 :

brew install android-sdk
brew cask install android-sdk

 

Step 2 : Extract platform-tools folder

sdkmanager "platform-tools" "platforms;android-28"

 

(the platform-tools will be according to the Android version. Refer: https://en.wikipedia.org/wiki/Android_version_history )

 

Step 3 : Add environment variables

 

ANDROID_HOME = path of android-sdk folder

PATH : append the path of platform-tools folder

export ANDROID_HOME=/usr/local/share/android-sdk
echo $ANDROID_HOME
export PATH="/usr/local/Caskroom/android-sdk/4333796/platform-tools:${PATH}"

 

#Set environment variables Globally on the Mac system use below mentioned command to execute

cd ~/
cat .bash_profile

 

If bash_profile does not exist

- touch .bash_profile
vi .bash_profile

 

Press i

 

Add the following

 

# Setting PATH for ANDROID_HOME

export ANDROID_HOME=/usr/local/share/android-sdk

 

# Adding platform-tools to PATH

PATH="/usr/local/Caskroom/android-sdk/4333796/platform-tools:${PATH}”

 

Press esc and type

:wq!

And press enter

 

 Now ANDROID HOME and PATH are set permanently 
  

echo $ANDROID_HOME
echo $PATH

 

   After this run command

adb devices

 

Step 4 : Now use mobile android device for automation

   Enable developer mode

   Enable USB debugging

 

Step 5 : Connect Android device with computer using usb cable

    if asked enable USB Debugging

   

Step 6 : Run command : adb devices

   Check device id is displayed