Mobile App Automation — Setup Appium & Android Studio

Sandhya
Property Finder Engineering and Tech Blog
6 min readSep 5, 2021

Introduction

Every product in market will have a mobile application in app store or play store to give users everything handy in their mobile. These needs to be tested as they get updated and are frequently used by users. Hence, these apps use cases should be automated. Considering the factors mentioned in the Automation-Choosing & Changing Tools & Framework blog we choose to perform mobile automation using appium. Since mobile applications in our organization are available both in andorid and ios,we choose appium as its supports both android and ios. Yes, there are other tools available in market but few support only ios and few only android.

In this blog lets learn how to setup appium and android to automate android application

What is Appium and Android studio?

Appium — its an open source test automation framework for use with native, hybrid and mobile apps. It drives IOS, Android, and Windows apps using the Webdriver protocol. It automates any mobile application from any languages like Ruby, Python, Java, JavaScript, PHP, C# and any test framework, with full access to back-end APIs and DBs.

Android Studio — is the official IDE for Google’s Android OS, built on JetBrains’ designed specifically for Android development, it can also be used in performing automation tests.

Appium setup

Let’s learn two ways to install it on your machine. Appium can be installed by command line or by desktop application.

Steps to install Appium desktop app:

  • install appium desktop from http://appium.io
  • Click on download, it redirects to the github page.
  • Click on the required file depending on the operating system you are using.
  • Here, for example, once a dmg file is downloaded, add it to application folder.
  • Click on the appium desktop application, it will look like this.
  • Click on “Start Server v1.17.0” to start using appium. All set!!!!

Steps to install Appium via command line:

As prerequisites, we need to verify that nodejs is installed on the machine by running

node -v

In case of nodejs not found on the machine, follow one of the below steps to install nodejs:

There are two different ways to install nodejs on the machine

  1. Install nodejs by downloading from https://nodejs.org/en/download/
  2. To install nodejs on mac using command line
Brew install node

Lets verify node and npm is installed on machine by running commands

node -v : returns the node version
npm — v : returns the npm version
which node : returns the path where it’s installed
which npm : returns the path where it’s installed

Do not forget, we still need to install appium by command line by running

npm install -g appium

As a best practice it is always a better idea to verify the installed software. To verify we have installed appium correctly lets run the following:

appium — version : returns the version installed
npm install appium-doctor -g : this installs appium-doctor which checks the installed appium
Verify by running command appium-doctor — android

To Uninstall appium run

npm uninstall -g appium in terminal

To delete app : uninstall appium desktop application

Steps to install Android studio and its required tools

  • Download from https://developer.android.com/studio .
  • On clicking download, accept the terms and conditions.
  • Click on the.dmg file and move the android studio to the application folder

For Windows — Go to download options on https://developer.android.com/studio page

Once android studio is installed, prerequisites should be set to run the android app tests smoothly. Run following commands on terminal to finish the complete setup

brew install android-sdk (homebrew should be installed before using brew). In case of download failure or any errors run brew cask install android-sdkrun cd tools/bin folder on terminal
run sdkmanager “platform-tools” “platforms;android-28

28 is the api level (always install equal or higher api level than the android version on phone)

set environment variables permanently on the Mac system

cd ~/
cat .bash_profile
If bash_profile does not exist — touch .bash_profile

Set android_home and platform_tools path

- Add in bash_profile
- export ANDROID_HOME=/usr/local/share/android-sdk
- PATH=”/usr/local/Caskroom/android-sdk/4333796/platform-tools:${PATH}”
- Save profile
run adb devices : this will list of devices connected or installed. - At first it does not return any device.Now, connect the phone to your laptop and run again. It returns the phone connected

Note — to make the phone available for testing, goto build number on phone and click 7 times to get developer options and enable Usb debugging.

Now, with the .apk file of the app we are all set to start automating tests for android applications. Appium server UiAutomator allows us to inspect the locators of the app and provides better understanding of layout. Android studio provides support for mobile and tv applications. Hence, applications in different versions of android can be automated and can be viewed in simulators provided by Android studio.

Few of the issues encountered during the setup and run:

  • Android version available in android studio in your system might not support the application you are trying to automate.
  • App path not being set correctly
  • Verify android home path is set before starting the automation.

Let’s check the setup by running calculator apk file.

  • Click on the play action, it opens the simulator
  • Now, open appium server
  • Set the desired capabilities, make sure you point to the right path of apk
  • Click on start session, it will open calculator app in simulator
  • Also, you can view app layout in appium server

Everything looks good!!!

In the next blog, will write in more details about how to structure our test cases and how to execute tests.

--

--