Appium Android Test (OSX)

In this post I will show you the basic steps to install appium on OSX by using the official App, to use the inspector and to run your first android test case.

Basic setup

The follwing packages are required:

  • Android SDK
  • Appium.app
  • JAVA

I had to do the following steps before I was able to run the inspector:

  • set JAVA_HOME (see instructions)
  • select your *.apk-file
    • click on the Android-Icon
    • enable App Path and select the path to your *.apk-file
  • enable "Prelaunch Application" in "General Settings"
  • set the android-sdk path in the advanced android settings:
    • click on the Android-Icon
    • click on Advanced tab
    • enable "Android SDK Path"
    • enter the path to your android sdk (e.g. content of your Android_Home Env-Var or see instructions)
  • (although it's available in the ENV Variable ANDROID_HOME. I think the problem is that I am a zsh user and the app will just load a bash or sh environment and so my ~/.zprofile will not be sourced).

Tips

Per Default you have to start your virtual device manually, but you can tell your Appium.app to do it for you:

  • open Appium.app
  • stop server if running
  • click on the android-icon
  • select basic settings-tab
  • enable "launch AVD" and enter the name of your virtual device

Write firsst testcase

Appium allows the usage of a lot of different programming lanuages (e.g. ruby, python, js,...). I will show how to write and run a simple test in python (source).

Requirements:

  • running appium server
  • python and pip already installed
pip install Appium-Python-Client

A first test case (for the official telegram android app) could look like this:

import os
import unittest
from appium import webdriver
from time import sleep

# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

class TelegramAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {
            'platformName':'Android',
            'app': PATH('../Telegram/TMessagesProj/build/outputs/apk/TMessagesProj-release.apk'),
            'appPackage': 'org.telegram.messenger',
            'appActivity':'org.telegram.ui.LaunchActivity'
        }

        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        self.driver.quit()

    def test_nothing(self):

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TelegramAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

Now you can run it like a normal python script:

python sample_tc.py

This test case does nothing special, but the script connects to the appium server, opens the app and launches the activity. You find your appActivity and appPackage arguments in your AndroidManifest.xml.