TestKase
TestKase
|Docs
AutomateMobile

First test in Python

A complete Appium test in Python you can copy, run, and watch on a real phone.

One file. Copy it, put your access key in, run it, and watch it happen on a real device.

What you need

Python 3.8 or newer, and one package:

pip install Appium-Python-Client

Nothing of ours to install. This is the ordinary Appium client.

The whole test

This drives our demo app, so there is nothing to upload — farm://app-sample is already on every device.

# first_mobile_test.py
import sys
import uuid

from appium import webdriver
from appium.options.ios import XCUITestOptions
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

ACCESS_KEY = "xyz_your_access_key_here"
HUB = f"https://x:{ACCESS_KEY}@hub.testkase.com/wd/hub"
TEST_NAME = "sign in"

options = XCUITestOptions()
options.device_name = "iPhone 16"
options.set_capability("appium:app", "farm://app-sample")
options.set_capability("testkase:options", {
    "name": TEST_NAME,
    "build": "first-test",
    "runId": str(uuid.uuid4()),
    "recording": True,
})

driver = webdriver.Remote(HUB, options=options)
wait = WebDriverWait(driver, 20)
print("session", driver.session_id)

try:
    wait.until(EC.visibility_of_element_located((AppiumBy.ACCESSIBILITY_ID, "login-email")))

    driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login-email").send_keys("test")
    driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login-password").send_keys("test")
    driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login-submit").click()

    # The tab bar only appears once sign-in succeeded.
    wait.until(EC.visibility_of_element_located((AppiumBy.ACCESSIBILITY_ID, "tab-counter")))

    driver.execute_script("testkase-status=passed")
    print("PASS ", TEST_NAME)

except Exception as err:
    driver.execute_script("testkase-status=failed")
    print("FAIL ", TEST_NAME, "->", err)
    driver.quit()
    sys.exit(1)

driver.quit()

Android instead? Import UiAutomator2Options from appium.options.android instead. Nothing else changes — our demo app uses the same accessibility ids on both platforms.

What each part does

Six things carry the whole file. Read down the middle column and you have its shape.

The partWhat it does
1https://x:[email protected]/wd/hubWhere your key goes. The same address serves desktop browsers and phones — the capabilities decide which you get.
2platformName: "iOS"Picks the platform. That is all you must send; leave the model and OS version out and you get whichever matching device is free.
3appium:appWhat to open. farm://app-sample is our demo app — nothing to upload, and it serves the right build for iOS, Android, real or virtual. Swap in your own id once you have uploaded a build.
4recording: trueSays what to keep. name is how you will recognise the session in a list; recording is the video, and you get none unless you ask. Every option.
5driver.find_element(AppiumBy.ACCESSIBILITY_ID, ...)Ordinary Appium from here on. Every command behaves exactly as it does against a phone on your desk — we only carry it to the device and back.
6testkase-status=passedHow we tell a pass from a crash. Without it the session shows no result. The failed one belongs in the catch, because a test that blows up skips every line after the blow-up.

Run it

python first_mobile_test.py

The console prints a session id, then PASS. Open your dashboard while it runs and you can watch the device live; when it ends, the video is on the session.