Test Your Native, Hybrid & Web Apps on 10,000+ real devices.

Learn how to use Appium with Python, run and scale tests on real devices, fix common issues, and follow best practices for mobile automation.
Last Modified on: December 7, 2025
Appium is a widely used open-source framework for automating mobile app testing across Android and iOS platforms. With Appium Python, you can efficiently automate tests for native, hybrid, and mobile web apps. Its integration with Python also enables writing readable, maintainable, and scalable test scripts.
Overview
Why Perform Appium Testing With Python?
Combining Appium with Python makes mobile automation easier, more flexible, and highly scalable for modern development teams. Here are the key reasons to use them together:
How to Perform Appium Testing With Python?
Running Appium with Python involves setting up the right tools, configuring the Android driver, writing a simple test case, and executing it on an emulator or real device. Here is the step-by-step process:
Appium works with any programming language, but using Python makes mobile test automation simple and efficient due to its readable syntax, fast development, and strong ecosystem.
New to Appium? Check out this Appium tutorial.
Benefits:
Note: Run Appium Python tests on real Android & iOS devices. Try LambdaTest Now!
Install Python, Android Studio, Node.js and Appium. Set up UiAutomator2. Use the Appium-Python-Client with pytest to launch the app, interact with elements, and run tests on an emulator or real device cloud offered by platforms like LambdaTest.
Let’s look at how to automate mobile app testing with the help of the Appium Python example:
npm install -g appiumappium -v
appium driver install uiautomator2appium driver listIt should output as follows:
- uiautomator2@5.0.5 [installed (npm)]
pip3 install Appium-Python-Client
pip3 install -U pytestIf you are new to the pytest framework, check out this pytest tutorial.
Now, we’ll look at how to automate Android apps with Appium. Let’s use the LambdaTest Proverbial app as a test URL for testing using Appium Python in Android.
Test Scenario:
Implementation:
Let’s create a proverbial_android_local_test.py file to implement the test scenario and write the first test with Appium.
import os.path
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.options.android import UiAutomator2Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
apk_path = os.path.abspath('./src/test/resources/proverbial_android.apk')
options = UiAutomator2Options().load_capabilities({
'platformName': 'Android',
'automationName': 'uiautomator2',
'deviceName': 'Pixel 6 API 34',
'app': apk_path
})
appium_server_url = 'http://localhost:4723'
class TestProverbialApp:
def setup_method(self):
self.driver = webdriver.Remote(appium_server_url, options=options)
def teardown_method(self):
if self.driver:
self.driver.quit()
def test_proverbial_text(self):
wait = WebDriverWait(self.driver, 20)
text_button = wait.until(EC.presence_of_element_located((AppiumBy.ID, "com.lambdatest.proverbial:id/Text")))
text_button.click()
text = self.driver.find_element(AppiumBy.ID, "com.lambdatest.proverbial:id/Textbox")
assert text.is_displayed(), "Proverbial"
The test is implemented by creating a TestProverbialApp class in the Python file. This class implements three primary methods: setup_method(self), teardown_method(self) and test_proverbial_text(self).
Code Walkthrough:
The test will be run on the Android Pixel emulator. To run the tests, follow the steps below:
appium --use-driver uiautomator2
pytest ./src/test/proverbial_android_local_test.pyThe following screenshot from the terminal shows that the test was run successfully.
Running tests locally can be tedious - starting Appium, launching emulators, and juggling device setups takes up time and resources. With a real device cloud offered by mobile app testing platforms such as LambdaTest, the same Appium Python tests run instantly on real Android and iOS devices without setting up an internal device lab.
To get started, check out this guide on Appium pytest testing with LambdaTest.
Now, to run the above test scenario on a real device cloud, follow these steps:
In the Upload window, select “Real Device” or “Virtual Device” based on your preference. Next, click on the “Browse File” button to upload the app.
After the app is uploaded, the app_url will be generated, which you can copy and paste into your Appium script.
Implementation:
Let’s add a conftest.py file and add all the configuration-related code to it.
def finalize_driver(request, driver):
def fin():
if request.node.rep_call.failed:
driver.execute_script('lambda-status=failed')
else:
driver.execute_script('lambda-status=passed')
driver.quit()
request.addfinalizer(fin)
@pytest.fixture(scope='function')
def test_setup_android(request):
test_name = request.node.name
caps = {
"lt:options": {
"w3c": True,
"platformName": "Android",
'deviceName': 'Galaxy S25',
'platformVersion': '15',
"isRealMobile": True,
"app": "lt://APP3467364763476",
"build": "Android Pytest",
"name": test_name
}
}
username = os.environ.get("LT_USERNAME")
access_key = os.environ.get("LT_ACCESS_KEY")
driver = webdriver.Remote("https://"+username+":"+access_key+"@mobile-hub.lambdatest.com/wd/hub",
options=UiAutomator2Options().load_capabilities(caps))
request.cls.driver = driver
yield driver
finalize_driver(request, driver)
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item,call):
# this sets the result as a test attribute for LambdaTest reporting.
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
# set an report attribute for each phase of a call, which can
# be "setup", "call", "teardown"
setattr(item, "rep_" + rep.when, rep)Code Walkthrough:
Let’s clean up the test file by removing the setup methods and leaving only the test in it.
@pytest.mark.usefixtures('test_setup_android')
class TestProverbialApp:
driver: WebDriver
def test_proverbial_text(self):
wait = WebDriverWait(self.driver, 20)
text_button = wait.until(EC.presence_of_element_located((AppiumBy.ID, "com.lambdatest.proverbial:id/Text")))
text_button.click()
text = self.driver.find_element(AppiumBy.ID, "com.lambdatest.proverbial:id/Textbox")
assert text.is_displayed(), "Proverbial"The @pytest.mark.usefixtures(“test_setup_android’) tells the test to use the fixture for setup. The driver instance is automatically assigned to self.driver by the fixture (via request.cls.driver = driver), making it available in all test methods of the class.
The test waits up to 20 seconds for a Text button to appear, clicks it, finds a Textbox element, and verifies it's displayed on the app screen.
Test Execution:
You can run the test using the following command:
pytest ./src/test/proverbial_android_cloud_test.pyThe following is a screenshot of the Appium Python test run on the LambdaTest real Android cloud platform, which shows details like the mobile device used, video recording of the test, steps performed in the test, and time taken to run the test.
Appium parallel testing is the way to execute multiple tests simultaneously, where tests can be run on multiple devices, platforms, and versions.
It provides multiple benefits, like reducing overall test execution time, providing faster feedback on builds, and achieving faster and more frequent releases to production.
Let’s look at the Python Appium example, where we’ll run the same test scenario in parallel on the following two real Android devices:
pip3 install pytest-xdistANDROID_DEVICES = [
{
"deviceName": "Galaxy S25",
"platformVersion": "15"
},
{
"deviceName": "Pixel 8",
"platformVersion": "14"
}
]def pytest_generate_tests(metafunc):
if 'device_config' in metafunc.fixturenames:
metafunc.parametrize('device_config', ANDROID_DEVICES, ids=lambda d: d['deviceName'])This pytest hook automatically generates multiple test variations from the ANDROID_DEVICES list in the devices.py file. Using this fixture, pytest runs the test separately for each device configuration in the list, using the device name to identify each test run.
@pytest.fixture(scope='function')
def test_setup_android(request, device_config):
test_name = request.node.name
caps = {
"lt:options": {
"w3c": True,
"platformName": "Android",
"deviceName": device_config['deviceName'],
"platformVersion": device_config['platformVersion'],
"isRealMobile": True,
"app": "lt://APP10160341071754500059009313",
"build": "Android Pytest",
"name": test_name
}
}
username = os.environ.get("LT_USERNAME")
access_key = os.environ.get("LT_ACCESS_KEY")
driver = webdriver.Remote("https://"+username+":"+access_key+"@mobile-hub.lambdatest.com/wd/hub",
options=UiAutomator2Options().load_capabilities(caps))
request.cls.driver = driver
yield driver
finalize_driver(request, driver)Test Execution:
Run the tests in parallel using the following command:
pytest -n 2 -vThis command runs the Appium Python tests in parallel using 2 worker processes (via pytest-xdist plugin). The -v enables verbose output to show detailed test results and progress.
Here is the screenshot from the LambdaTest cloud platform showing the parallel test execution details:
Below are common issues faced during Python Appium automation, along with their resolutions:
Running mobile automation tests with Python and Appium works best with a clear strategy to build reliable and maintainable test suites.
Here are the following best practices for more efficient Appium mobile testing with Python:
In this Appium with Python tutorial, we explored how Appium combines cross-platform coverage with the Python language, which is easy to read, write, and maintain. From basic execution to running tests on real devices and in parallel, the Appium framework supports both scale and stability.
With an understanding of troubleshooting and best practices, you can build reliable automation with Appium using Python that improves test coverage, speeds up releases, and maintains consistent app quality over time.
Did you find this page helpful?
More Related Hubs
Start your journey with LambdaTest
Get 100 minutes of automation test minutes FREE!!