Appium Integration for Pytest Framework
Step 1: Install Android Studio and Set Up Environment Variables
- Download and Install
Visit the Android Studio website and download the installer for your OS.
Run the installer and follow the setup wizard to install Android Studio and required SDK components.
- Install Android Studio
Run the downloaded installer.
Follow the installation wizard steps.
During installation, select the necessary SDK components.
- Verify Installation
Open Android Studio after installation.
Complete the setup wizard to ensure all SDK components are installed.
- Set Up Environment Variables (Windows)
Open System Properties → Environment Variables.
Add a new System Variable:
Name: ANDROID_HOME Paste following path into the value column C:\Users{userName}\AppData\Local\Android\Sdk
Then Add below into path variable:
%Android_Home%\platform-tools
%Android_Home%\tools
%Android_Home%\build-tools
Restart your terminal or IDE.
Step 2: Install Gradle and Set Up Environment Variables
- Download Gradle
Visit the Gradle website and download the Complete distribution.
- Extract Gradle
Extract the downloaded ZIP file to a preferred location (e.g., C:\Gradle).
- Set Up Environment Variables (Windows)
Open System Properties → Environment Variables.
Add a new System Variable:
Name: GRADLE_HOME
Value: Path to the Gradle folder (e.g., C:\Gradle\gradle-x.x).
Update the Path variable under System Variables:
Add: %GRADLE_HOME%\bin
Save changes and restart your terminal or IDE.
Step 3: Install Appium Inspector
- Download Appium Inspector
Go to the Appium Inspector GitHub page.
Download the installer for your operating system.
- Install Appium Inspector
Run the downloaded installer and follow the instructions to complete the installation.
- Verify Installation
Launch Appium Inspector to ensure it's installed and working correctly.
Step 4: Install Java 11
- Download Java 11
Visit the Oracle Java Downloads page or OpenJDK page.
Download the Java 11 installer for your operating system.
- Install Java 11
Run the installer and follow the instructions to complete the installation.
Note the installation path (e.g., C:\Program Files\Java\jdk-11.x.x).
- Set Up Environment Variables (Windows)
Open System Properties → Environment Variables.
Add a new System Variable:
Name: JAVA_HOME
Value: Path to the Java installation folder (e.g., C:\Program Files\Java\jdk-11.x.x).
Update the Path variable under System Variables:
Add: %JAVA_HOME%\bin
Save changes and restart your terminal or IDE.
- Verify Installation
Open a terminal and run:
java -version
Ensure it shows Java 11.
Step 5: Install and Set Up Appium Server
- Install Appium Server
Install Appium globally using Node.js:
npm install -g appium
- Verify Installation
Check if Appium is installed correctly:
appium --version
- Start Appium Server
Run the following command to start the Appium server:
appium -p 4723
The server will start and listen on the default port 4723.
Step 6: Install UIAutomator2 Driver
- Install the Driver
Use the following Appium command to install the UIAutomator2 driver:
appium driver install uiautomator2
- Verify Installation
Check if the UIAutomator2 driver is installed by listing all installed drivers:
appium driver list
Ensure uiautomator2 appears in the list.
- Configure the Driver
UIAutomator2 is typically the default driver for Android devices. No additional configuration is required unless you need specific capabilities.
- Install Chromium Driver
Run:
npm install appium-chromedriver
Step 7: Install and Set Up Python
- Download Python
Visit the Python website and download the latest version of Python 3.x.
- Install Python
Run the installer and check the option "Add Python to PATH" before starting the installation.
Follow the installation steps to complete the setup.
- Verify Installation
Open a terminal and run:
python --version
Ensure it displays the installed Python version.
- Install pip (if not installed)
Run the following command to ensure pip, the Python package manager, is installed:
python -m ensurepip --upgrade
- Set Up Virtual Environment (Optional)
Create a virtual environment for your project:
python -m venv venv
Activate the virtual environment:
Windows: venv\Scripts\activate
macOS/Linux: source venv/bin/activate
Step 8: Create a Virtual Device in Android Studio
- Open AVD Manager
Launch Android Studio.
Navigate to Tools → Device Manager (or AVD Manager).
- Create a New Virtual Device
Click on Create Device.
Select a device model from the list (e.g., Pixel 4) and click Next.
- Choose a System Image
Select the desired Android version (e.g., Android 14.0).
Download the system image if not already available and click Next.
- Configure the Virtual Device
Set the device orientation, scale, and other preferences.
Click Finish to create the virtual device.
- Start the Virtual Device
In the Device Manager, click the Play button next to the virtual device to launch it.
Step 9: Install Telegram App on the Android Virtual Device
- Launch the Virtual Device
Open Android Studio → Device Manager → Start your virtual device.
- Open Google Play Store
Navigate to the Google Play Store app on the virtual device.
Sign in with your Google account if prompted.
- Search for Telegram
Use the search bar to find the Telegram app.
- Install Telegram
Select the Telegram app from the search results.
Click Install and wait for the installation to complete.
- Verify Installation
Open the Telegram app to ensure it launches successfully.
Step 10: Install PyCharm and Set Up Appium Python Client 3.0
- Download PyCharm
Visit the PyCharm website and download the appropriate version for your operating system.
- Install PyCharm
Run the installer and follow the setup instructions to complete the installation.
- Install Appium Python Client 3.0
Open a terminal or PyCharm’s terminal and run the following command to install the Appium Python client:
pip install Appium-Python-Client==3.0
- Verify Installation
In PyCharm, create a new Python file and import the Appium client to check if it's installed correctly:
from appium import webdriver
- Configure PyCharm for Appium Python Development
Open PyCharm and configure the Python interpreter for your project (using the virtual environment, if created).
Ensure all dependencies are set up for your Appium Python framework.
Step 11: Clone the Git Repository into Local
- Install Git (if not already installed)
Visit the Git website and download the latest version of Git for your operating system.
Follow the installation instructions to complete the setup.
- Open Git Bash
Launch Git Bash from the Start menu or applications folder.
- Clone the Repository
In Git Bash, navigate to the folder where you want to clone the repository using the cd command.
Run the following command to clone the repository:
git clone
Replace with the actual URL of your Git repository.
- Verify the Clone
Navigate into the cloned directory:
cd
List the files to ensure the repository has been cloned:
ls
Step 12: Create a Virtual Environment for pytest
- Navigate to Your Project Directory
Open a terminal and navigate to your project folder (where the Appium framework is cloned):
cd
- Create a Virtual Environment
Run the following command to create a virtual environment:
python -m venv venv
- Activate the Virtual Environment
Windows:
venv\Scripts\activate
macOS/Linux:
source venv/bin/activate
- Install pytest
Once the virtual environment is activated, install pytest:
pip install pytest
- Verify Installation
Check if pytest is installed correctly:
pytest --version
Step 13: Start AVD and Appium Server
- Start the AVD
Open Android Studio → Device Manager and click the Play button next to your virtual device to launch it.
- Ensure the Device is Detected
Open a terminal and run the following command to check if the device is detected:
adb devices
Ensure your device is listed under "List of devices attached".
- Start the Appium Server
In the terminal, start the Appium server by running:
appium -p 4723
This will start the Appium server on port 4723.
Step 14: Run the Test in Telegram_demo.py
- Open the Test File
Open your test file (e.g., Telegram_demo.py) in your preferred editor (e.g., PyCharm).
- Ensure AVD is Running
Verify that your Android Virtual Device (AVD) is turned on and running by checking if the device is visible in Device Manager in Android Studio.
- Run the Test Using pytest in Terminal
In PyCharm's terminal, run the test using pytest:
pytest -k test_send_message
This will execute the test_send_message() test case from the Telegram_demo.py file.
- Run the Test Using Test Explorer in PyCharm
In PyCharm, open the Run menu and select Run 'pytest'.
Alternatively, you can click on the Test Explorer window on the right side of PyCharm.
Find the test case test_send_message in the list of available tests and click the Run button (green triangle) next to it.
- Verify Test Execution
Ensure that the test passes and
Value: Path to the Android SDK (e.g., C:\Users<YourUsername>\AppData\Local\Android\Sdk).
Update the Path variable under System Variables: that the message is sent successfully on the Telegram app running on the AVD.