21 Apr

Appium with Python


Appium is an open source test automation tool for mobile applications. It allows you to test all the three types of mobile applications: native, hybrid and mobile web. It uses JSON wire protocol internally to interact with Android and iOS native apps using the Selenium WebDriver. 

It also allows you to run the automated tests on

  • Real devices
  • Emulators
  • Simulators

How to Download Appium?

Please click “Download Appium” in the below link


Install Appium Python Client:

Please follow below link to install Python2.7 and Eclipse editor for creating Python projects.


To install Appium Python Client, please follow below link


How to setup Appium on Android Platform?

Appium supports Android on OS X, Linux and Windows OS. 

In this blog, we will discuss Android on Windows OS.

Download Android SDK from below link


To install Android SDK follow below video link


Connect Android Phone to Windows OS system via USB cable and enable “Developer options” by navigating to Settings/About Phone and tapping build number seven times.You will get a notification saying that you’re now a developer.

Once you are a developer you need to navigate to “Developer options” and enable the USB debugging option.

On Android phone, install “Application Reader” app from Google play store. Application Reader app is used get the app Package and Activity details, which is used for testing the application.

Now open command prompt, navigate to Android SDK tools path and run the command to open Uiautomatorviewer.

To capture a screen, click the “Device Screenshot button” in the uiautomatorviewer tool. The screenshot of the page in your device is captured. You can move over the snapshot in the left-hand panel to see the UI components identified by the uiautomatorviewer.

Start the Appium application by double clicking the .exe file.

Sample Appium Program:

Here is the sample Appium program using Python to get temperature of location using “Weather” app. We need to install weather app before running this code.

# -*- coding: utf-8 -*-


Author : Gandhi Gonugunta


import unittest, time, os

from appium import webdriver

import time

class Android_WeatherApp_Test(unittest.TestCase):


    def setUp(self):


        desired_caps = {}

        desired_caps[‘platformName’] = ‘Android’

        desired_caps[‘platformVersion’] = ‘6.0’

        desired_caps[‘deviceName’] = ‘MyPhone’


        desired_caps[‘appPackage’] = ‘com.macropinch.swan’

        desired_caps[‘appActivity’] = ‘com.macropinch.swan.WeatherActivity2’


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

    def tearDown(self):

        “Tear down the test”


    def test_wifi(self):



        print “In Weather App..”

        #city = raw_input(“Enter the city name to be checked: “)

        ## Checking the Weather in Hyderabad Location

        city = “Hyderabad”

        city = city.title()

       getcity = self.driver.find_element_by_xpath(“//android.widget.TextView[@index=’0′]”)


        if city not in getcity.get_attribute(‘text’):

            mcity = self.driver.find_element_by_xpath(“//android.widget.TextView[@index=’0′]”)


            tempcity = self.driver.find_element_by_xpath(“//android.widget.TextView[@resource-id=’android:id/text1′]”)



        print “Checking temperature in Hyderabad Area..”

        gettemp = self.driver.find_element_by_xpath(“//android.widget.TextView[@index=’1′]”)

        print “Temp is :”,gettemp.get_attribute(‘text’)


if __name__ == ‘__main__’:

    suite = unittest.TestLoader().loadTestsFromTestCase(Android_WeatherApp_Test)


Please edit below lines in the code:

desired_caps[‘platformVersion’] = ‘6.0’   -> Your Android phone platform version(Settings/About Phone)

desired_caps[‘deviceName’] = ‘MyPhone’ -> Your Andriod phone Name

Use Application Reader app to get appPackage & appActivity and edit below two lines,

desired_caps[‘appPackage’] = ‘com.macropinch.swan’

desired_caps[‘appActivity’] = ‘com.macropinch.swan.WeatherActivity2’





Share this

Leave a reply