How to Power Mobile Test Automation with Appium + Pytest

May 2, 2025

How to Power Mobile Test Automation with Appium + Pytest

Set up Appium with Pytest for fast, modular mobile test automation. Learn tools, structure, and tips to streamline Android and iOS testing workflows.

Author

Pavitra Kinni
Pavitra KinniSoftware Engineer in Testing - II

While Appium is a go-to for mobile automation and Pytest is a favorite in the Python ecosystem, using them together is surprisingly rare. This article breaks down why this combo is powerful, how we made it work, and how you can, too.

Why Appium + Pytest?

  • Appium gives cross-platform mobile automation (Android/iOS)
  • Pytest offers elegant test writing, fixtures, and plugin support
  • Most teams use Appium with Java/TestNG โ€” but if your stack is Python-heavy, Pytest is a perfect fit

Use case at our org: We needed mobile UI + API integration tests running inside a unified framework. Pytest gave us modularity and speed, while Appium handled real device automation.

Pre-requisites for Appium + Pytest Setup on Mac

1. Install Homebrew (if not already installed)

Homebrew helps install packages easily on Mac.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install Python 3

brew install python

 3. Install Pip and Virtual Environment

python3 -m ensurepip --upgrade

Create and activate a virtual environment (recommended):

python3 -m venv venv

source venv/bin/activate

4. Install Appium Server

You can install Appium globally using npm (Node Package Manager).
First, install Node.js: brew install node
Then install Appium: npm install -g appium
Verify Appium: appium -v

5. Install Appium Doctor

To check your environment setup easily:
npm install -g appium-doctor
appium-doctor

6. Install Android Studio

7. Install Appium-Python-Client and Pytest

Inside your virtual environment: pip install Appium-Python-Client pytest
Optional but useful: pip install pytest-xdist pytest-html

8. Enable Developer Mode on Your Mobile Device    (Android or iOS)

If you are using a physical device:

  • Enable Developer Options and USB Debugging (Android).

  • For iOS, configure WebDriverAgent (more setup needed).

9. Start Appium Server

Run via Terminal: appium

10. ADB Devices Check (Android)

Verify that your device/emulator is connected: adb devices

You should see your device ID listed.

After Setup

Youโ€™ll be ready to:

  • Launch Appium server
  • Connect an emulator or device
  • Run pytest-based test cases using Appium driver sessions!

Directory structure:

mobile_automation/

โ”œโ”€โ”€ tests/

โ”‚   โ””โ”€โ”€ test_demow.py

โ”œโ”€โ”€ pages/

โ”‚   โ””โ”€โ”€ demo_page.py

โ”œโ”€โ”€ utils/

โ”‚   โ””โ”€โ”€ driver_setup.py

โ”œโ”€โ”€ conftest.py


 1. driver_setup.py

import os
from appium import webdriver
from appium.options.android.uiautomator2.base import UiAutomator2Options

def get_driver():
   appium_url = "http://127.0.0.1:4723"
   desired_caps = {
       "platformName": "Android",
       "deviceName": "Pixel_8",
       "appPackage": "io.appium.android.apis",
       "appActivity": "io.appium.android.apis.ApiDemos",
       "automationName": "UiAutomator2"
   }
   options = UiAutomator2Options().load_capabilities(desired_caps)


   driver= webdriver.Remote(command_executor=appium_url, options=options) 
   return driver

 2. conftest.py (with Pytest Fixture)

import pytest
from drivers.driver_setup import get_driver

@pytest.fixture(scope="function")
def driver():
   driver = get_driver()
   yield driver
   driver.quit()

3. Page Object: demo_page.py

import time
from appium.webdriver.common.appiumby import AppiumBy

class DemoPage:
   def __init__(self, driver):
       self.driver = driver


   def press(self):
       self.driver.find_element(AppiumBy.XPATH, "//android.widget.TextView[@content-desc=\"Accessibility\"]").click()

4. Test File: test_demo.py

import pytest
from Pages.demo_page import DemoPage

def test_addition(driver):
   obj_button = DemoPage(driver)
   obj_button.press()

5. Command to run the pytest file: pytest -vs tests/test_demo.py(pytest with the relative path)

output of pytest

Challenges

  • Issue: pytest not detecting Android environment
  • Fix: Ensure pytest runs from the project root with PYTHONPATH= pytest
  • Issue: Flaky UI loading
  • Fix: Added explicit waits and fallback API validations

The Benefits of This Stack

  • Unified Python automation for web + mobile + API
  • Reusable Pytest fixtures
  • Super fast local debugging
  • Easily scalable with Allure reports

Final Thoughts

Appium + Pytest might not be the default combo, but it can be the perfect fit for teams looking to unify their testing across layers. With good structure and the right fixtures, itโ€™s fast, flexible, and fun to work with

Subscribe to Our Newsletter

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Building Local LLMs Using Dart FFI And llama.cpp: Beyond Wrapper Packages
Sep 11, 2026

Building Local LLMs Using Dart FFI And llama.cpp: Beyond Wrapper Packages

Build local LLMs in Flutter with Dart FFI and llama.cpp, and see how native bridges, GGUF models, memory management, and token streaming enable private, on-device AI.

Insight
My Flutter App Froze With Three Photos on Screen. Here's What I Was Doing Wrong
Sep 11, 2026

My Flutter App Froze With Three Photos on Screen. Here's What I Was Doing Wrong

This blog explains how rethinking Flutterโ€™s image-processing architecture fixed severe performance issues and improved rendering efficiency.

Insight
Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15
Sep 10, 2026

Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15

This blog explains how to build a production-ready canvas editor with Konva.js, React, and Next.js, covering architecture, performance, and key engineering decisions.

Insight
What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust
Sep 8, 2026

What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust

This blog explores the architecture, security, performance, and documentation lessons from migrating a legacy PHP/Laravel banking platform to NestJS.

Insight
Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs
Sep 7, 2026

Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs

This blog explains how to build responsive video thumbnail scrubbing in the browser for local files and HLS streams, covering frame extraction, caching, and performance trade-offs.

Insight
The Agent Can See Your App. How Often Can It Look?
Sep 4, 2026

The Agent Can See Your App. How Often Can It Look?

AI coding agents can now interact with mobile apps, but their effectiveness depends on iteration speed. This blog explores how React Native architecture influences feedback loops and AI-driven developer productivity.

Insight
Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists
Sep 1, 2026

Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists

Learn how to turn design JSON into interactive, video-enabled cards using overlays, smart media controls, caching, and virtualization without slowing down high-cardinality feeds.

The Right Conversation Can

Save You Six Months.

Book a call