Appium + Python: Environment Setup and a Simple Mobile Automation Demo
This guide walks through installing the required tools, configuring Appium with Python on Windows, extracting an Android app's package and activity, writing a basic automation script, launching the app, using uiautomatorviewer for element location, and applying tips for Chinese input and service timeout handling.
Appium is a popular automation framework that supports both Android and iOS, and allows scripts in Java or Python; this article demonstrates a simple automation flow using Appium with Python.
Environment Configuration
Required tools (Windows 7 64‑bit): Python 2.7 (or 3.6), Appium 1.5.2, Appium‑Python‑Client, JDK 1.8 (64‑bit), Android SDK, PyCharm, ADB (included with the SDK), and optionally Node.js for npm installation of Appium.
Step 1 – Obtain Package and Activity Names
Run the following command after launching the target app: adb shell dumpsys activity > d:/package.txt Open the generated package.txt and search for "cmp" to find the package name (e.g., com.xxx.cloudrefactor) and the launch activity (e.g., MainActivity).
Step 2 – Write the Automation Script
The Python script includes key capabilities: platformName: mobile OS deviceName: device identifier platformVersion: OS version appPackage: target app package appActivity: launch activity
webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps): connects to the default Appium server
After saving the script, start the Appium server and click the "Start" button in the GUI.
Step 3 – Launch the Application
With the server running, execute the Python script; the app will start automatically on the connected device.
Step 4 – Element Location with uiautomatorviewer
Use the Android SDK tool uiautomatorviewer to capture the UI hierarchy, then locate elements by text, resource-id, or class. Example of clicking an element using resource-id: driver.find_element_by_id('com.example:id/button').click() This two‑line snippet can be combined with the launch script to perform a click action.
Tips
1. Chinese Input : Add the following capabilities to enable Unicode keyboard input:
"unicodeKeyboard":"True" "resetKeyboard":"True"2. Appium Service Timeout : The default session timeout is 60 seconds. To extend it, start Appium with the argument --command-timeout 600 (e.g., main.js --command-timeout 600) to prevent the service from stopping during long idle periods.
These steps provide a complete, end‑to‑end example of setting up and running a basic mobile automation test with Appium and Python.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
