text
Integrating Mobile Automation With Appium In Python

Join

Subscribe to our Newsletter

As there is an understanding among testers that getting commenced with mobile automation is difficult. We strongly believe that a tester must possess a broad range of skills. You do not require to be a specialist in all of them, but it is very crucial to have pondered a spectrum of concepts and explored a variation of tools. The context under which you assess will notify you of the particular choice of the testing procedure and test tools to select. The more choices you are familiar with, the better your context-specific option is going to be. 

In this view, we started seeing that mobile testing has become relatively of a niche among testers. Testers are unwilling to get begun with mobile testing, maybe because they think getting started includes a ton of time and action. This blog will look at the python appium framework, mobile automation using python. We will also focus on appium testing using Python as a programming language and appium mobile automation testing from basics to the framework. Furthermore, we are concentrating only on the “getting started” stage. The tools your test team utilizes to solve the particular and unique problems can extensively differ. Let’s look at the history of the python appium framework.

History Of Python Appium Framework 

On the eve of Christmas 2013, Selenium officially departed their AndroidDriver and iPhoneDriver in approval of its driver, Selendroid, and Appium. Appium and Python are a great combination of Mobile automation. Python existing as an Interpreted, high-level programming language proposes a quicker development time.

Appium is an open-source tool you can utilize to automate mobile web, mobile native, and mobile hybrid applications on iOS and Android outlets. Appium is “cross-platform” as it enables you to write tests on many platforms like iOS, Android, etc, utilizing the same API. This facilitates a huge or total amount of code reutilization between iOS and Android test suites.

Appium Testing Using Python

This section is a fast start for a primary mobile app automation test utilizing Appium Python testing. The sample project is evolved in Pycharm IDE and for an Android device. 

Following are the requirements below:

  1. The latest edition of Java, required for Android Studio.
  2. Installation of Android Studio with SDK. This is required since ADB gets installed as part of the Android SDK. The ADB utility is proposed to get the device list related to the PC.
  3. Download sample Android application called Eribank using the link https://experitest.s3.amazonaws.com/eribank.apk
  4. Installation of the latest edition of PyCharm.
  5. By connecting the Mobile device to the PC using a USB cable and facilitating the developer mode or USB debugging in the Android device.

Now let’s look at the setup of appium.

Appium setup

Here are the following steps to setup Appium on Windows 7 and utilize it with an Android emulator.

1. Download the recent Appium

The first step is to download the latest appium and you can run the exe to install the appium desktop app.

2. Download and Install Android Studio

Once you install Android Studio mark the AVD Manager is further installed as we are moving to drive our tests on an emulator. Set ANDROID_HOME to be your Android SDK path and put in the tools and platform-tools folders to your PATH variable. 

3. Install the Java JDK

Now install the Java JDK and set JAVA_HOME to your JDK folder

4. Install the Python client library

There are client libraries in Java, Python, PHP, Ruby, C# and JavaScript, and that support Appium’s additions to the WebDriver strategy. While using Appium, you like to utilize these client libraries rather than your regular WebDriver client. You are now set up.

5. Begin the Android Virtual Device (AVD), Manager

Begin the Android Studio and launch the Android Virtual Device (AVD) Manager by clicking.

AVD_Manager

Build an emulator with the choices you require and launch it using the start button

android_emulator

6. Start the Appium server console

Begin the Appium server console by double-clicking on the Appium file.

start_appium

7. Launch the Appium node server

You should click on the ‘rocket’ icon to launch the Appium node server

Launch_Appium

appium_node_server_console

Your first test using Appium

For this test, we will use the highly suggested Chess Free application built by the UK-based AI Factory. For this post, we will simulate that our test is to launch the application and click on the “PLAY” button.

1. Acquire the .apk for the application under test

We acquired the .apk for Chess Free over here. Copy the chess application to a directory of your preference. 

2. Glance into the AndroidManifest.xml

To compose the test, you require two pieces of data specific to your application:

  • Java package of the Android app you wish to drive
  • The name of the activity for the Android activity you wish to launch your package

You can receive this information by running the subsequent command:

ANDROID_HOME\sdk\build-tools\android-4.4.2>aapt dump badging path_to_apk_file

aapt_pkg_activity

Another strategy is utilizing the AndroidManifest.xml which is existing in the origin directory of all Android applications and has the data we require. You can utilize Android Studio to discern the AndroidManifest.xml file. Go to Build/Analyze APK and choose your apk. Then you can view the content of the AndroidManifest file.

package=”uk.co.aifactory.chess free” and 

android:name=”.ChessFreeActivity”

3. Write the test

Build a test script in $Directory_Of_My_Choice established on the snippet. You should give any specific attention to the setup procedure.

The test will:

– launch the app

– Click the ‘PLAY!’ button

import os

import unittest

from appium import web driver

from time import sleep

class ChessAndroidTests(unittest.TestCase):

       def setUp(self):

        “Setup for the test”

        desired_caps = {}

        desired_caps[‘platformName’] = ‘Android’

        desired_caps[‘platformVersion’] = ‘8.0’

        desired_caps[‘deviceName’] = ‘Pixel’

        desired_caps[‘app’] = os.path.abspath(os.path.join(os.path.dirname(__file__),’apps/Chess Free.apk’))

        desired_caps[‘appPackage’] = ‘uk.co.aifactory.chess free’

        desired_caps[‘appActivity’] = ‘.ChessFreeActivity’

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

    def tearDown(self):

        “Tear down the test”

        self.driver.quit()

    def test_single_player_mode(self):

               element = self.driver.find_element_by_id(“uk.co.aifactory.chess free:id/ButtonPlay”)

        element.click()

        sleep(5)

#—START OF SCRIPT

if __name__ == ‘__main__’:

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

    unittest.TextTestRunner(verbosity=2).run(suite)

4. Run the test

Run the script android_chess.py. The chess application is launched in the test emulator

Run_Chess_App

5. Check the outcome

appium_test_run

Celebrate a little because you only upgrade your skills by a little bit in a very small period!

There you possess it as you have just run your first mobile automated test with Appium and Python. We now dwell in the mobile world more than ever. Further industries are concentrated on building mobile apps for their enterprises. Users presently spend most of their virtual time on their mobile devices utilizing a collection of apps. When the user is interacting with these apps, he or she may be needing a specific level of quality, but with an ever-growing mobile world, this can be difficult.

This is where Test Automation arrives. Since we utilize it to only automate web applications utilizing Selenium. However now, we can carry that knowledge and assign it to mobile using Appium. As we have learned everything about the python appium framework in this tutorial. If you have any queries or comments do not hesitate to reach out to us. We’ll be happy to help you. 

Contact Us

Hire vetted developers & testers with Appsierra to build & scale your software products

Trusted by 100x of startups and enterprise companies like

Read More

Subscribe to Our Newsletter