Getting Started: Run Appium Tests on TestMu AI
Running your first Appium test on TestMu AI executes native and hybrid mobile app End-to-End (E2E) testing on real Android and iOS devices. Clone a sample project, set credentials, upload your app, configure desired capabilities, and view detailed results on the dashboard.
- A TestMu AI account. Sign up if you don't have one.
- Your Username and Access Key from the TestMu AI Profile page.
- An Android app (
.apkor.aab) or an iOS app (.ipa). No app yet? Use the sample Android app or iOS app. - The Appium client for your language:
- Python: Python 3 and the Appium Python Client 2.3.0 or later.
- Java: a JDK and the Appium Java client (
io.appium:java-client) in your Maven or Gradle project. Use the latest release: this sample was tested with java-client 11.0.0.
Appium is an open-source framework that lets you perform End-to-End (E2E) testing of mobile applications. It works across different platforms like Android and iOS, enabling you to write tests once and run them on various devices.
Appium leverages the WebDriver protocol, similar to how Selenium automates web applications. This makes it compatible with popular programming languages for writing test scripts.
Here is a list of languages and frameworks that are supported by the TestMu AI to run Appium automation tests on TestMu AI Real Device Cloud Platform.
We support all languages and frameworks that are compatible with Selenium, so in case your favorite isn't in the table.
Don't worry, you can still run the test. Contact Us for any help.
- Python
- Java
import os
from appium import webdriver
from appium.options.common import AppiumOptions
lt_options = {
"platformName": "android",
"deviceName": "Galaxy S23",
"platformVersion": "14",
"app": os.environ["LT_APP_URL"],
"isRealMobile": True,
"build": "Appium quickstart",
"name": "First Appium test",
"devicelog": True,
"w3c": True,
}
options = AppiumOptions()
options.set_capability("platformName", "android")
options.set_capability("LT:Options", lt_options)
hub = f"https://{os.environ['LT_USERNAME']}:{os.environ['LT_ACCESS_KEY']}@mobile-hub.lambdatest.com/wd/hub"
driver = webdriver.Remote(command_executor=hub, options=options)
try:
# Add your test steps here
driver.execute_script("lambda-status=passed")
except Exception:
driver.execute_script("lambda-status=failed")
raise
finally:
driver.quit()
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.MutableCapabilities;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class FirstAppiumTest {
public static void main(String[] args) throws Exception {
Map<String, Object> ltOptions = new HashMap<>();
ltOptions.put("platformName", "android");
ltOptions.put("deviceName", "Galaxy S23");
ltOptions.put("platformVersion", "14");
ltOptions.put("app", System.getenv("LT_APP_URL"));
ltOptions.put("isRealMobile", true);
ltOptions.put("build", "Appium quickstart");
ltOptions.put("name", "First Appium test");
ltOptions.put("devicelog", true);
ltOptions.put("w3c", true);
MutableCapabilities caps = new MutableCapabilities();
caps.setCapability("platformName", "android");
caps.setCapability("LT:Options", ltOptions);
String hub = "https://" + System.getenv("LT_USERNAME") + ":" + System.getenv("LT_ACCESS_KEY")
+ "@mobile-hub.lambdatest.com/wd/hub";
AndroidDriver driver = new AndroidDriver(new URL(hub), caps);
try {
// Add your test steps here
driver.executeScript("lambda-status=passed");
} catch (Exception e) {
driver.executeScript("lambda-status=failed");
throw e;
} finally {
driver.quit();
}
}
}
Replace the # Add your test steps here comment with your own steps. lambda-status marks the session passed or failed on the dashboard.
To run on iOS, upload an .ipa in Step 2, set platformName to ios in both places, and set deviceName and platformVersion to an iPhone model and iOS version from the Capabilities Generator. In Java, use IOSDriver (io.appium.java_client.ios.IOSDriver) in place of AndroidDriver.
Capabilities Used in This Test
| Key | Example | Purpose |
|---|---|---|
platformName | android or ios | OS family. Set it at the top level and inside LT:Options. |
deviceName | Galaxy S23 | Device model, spelled exactly as the Capabilities Generator lists it. |
platformVersion | 14 | OS version of that device. |
app | lt://APP123456789123456789 | The app_url from Step 2, read from LT_APP_URL. |
isRealMobile | true | Runs on a real device. Set it to false to run on an emulator or simulator. |
build / name | Appium quickstart / First Appium test | Build and test names on the dashboard. |
devicelog | true | Captures device logs. Off by default. |
w3c | true | Uses the W3C WebDriver protocol. |
Video recording (video) is on by default, and Appium logs are always captured. Set network to true for network logs. Generate a capability set for any device and OS version with the Capabilities Generator, and see Appium desired capabilities on TestMu AI for every supported key.
Run the Test and View Results
- Python
- Java
pip install Appium-Python-Client
python3 first_test.py
If python3 is not recognized, use python instead.
Add io.appium:java-client to your pom.xml or build.gradle, then run the FirstAppiumTest class from your IDE or build tool. Start it from the same shell that holds LT_USERNAME, LT_ACCESS_KEY and LT_APP_URL, or set them in your IDE's run configuration.
Open the App Automation Dashboard. The run appears under the build Appium quickstart with the test First Appium test, marked passed or failed by lambda-status. The session holds the video recording, the Appium logs and the device logs. For a tour of the dashboard, see App Automation Dashboard.
Test a Locally Hosted App With the Tunnel
A real device in the cloud can't reach localhost, a private staging server or a backend behind your firewall. Route the session through TestMu AI Tunnel so the device can reach them.
- Download the Tunnel binary for your operating system:
- Extract the file, open a terminal in that folder and start the Tunnel. On Windows, run
LTwith the same flags.
./LT --user "$LT_USERNAME" --key "$LT_ACCESS_KEY" --tunnelName my-tunnel
- With the Tunnel running, add these keys to
LT:Optionsand run the test again:
| Key | Example | Purpose |
|---|---|---|
tunnel | true | Routes the session through the Tunnel. |
tunnelName | my-tunnel | The name you passed to --tunnelName. With a single tunnel, tunnel: true alone is enough. |
For proxies, several tunnels and other options, see testing locally hosted apps and TestMu AI Tunnel.
Run Appium Tests in CI
In CI, store your username and access key as secrets, expose them as LT_USERNAME and LT_ACCESS_KEY, upload each new build, and pass its app_url to the test as LT_APP_URL. The test code from Step 3 doesn't change. This GitHub Actions workflow runs the Python test on every push:
name: Appium tests
on: [push]
jobs:
appium:
runs-on: ubuntu-latest
env:
LT_USERNAME: ${{ secrets.LT_USERNAME }}
LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install Appium-Python-Client
- name: Upload the app
run: |
APP_URL=$(curl -s -u "$LT_USERNAME:$LT_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@path/to/your-app.apk" -F "name=ci-build" | jq -r '.app_url')
echo "LT_APP_URL=$APP_URL" >> "$GITHUB_ENV"
- run: python first_test.py
Replace path/to/your-app.apk with your build output. For Jenkins, GitLab CI, CircleCI, Bitbucket Pipelines and other tools, see CI/CD integrations.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
401 Unauthorized | LT_USERNAME or LT_ACCESS_KEY is unset, stale or missing from the hub URL. | Run echo $LT_USERNAME, then copy both values again from the Access Key button on the dashboard. A test started from an IDE may not inherit your terminal's variables. |
App not found, or the app capability is rejected | LT_APP_URL is empty, a local file path, or an lt:// ID that no longer exists. Apps unused for 30 days are removed automatically. | Upload the app again and set LT_APP_URL to the new app_url. |
SessionNotCreatedException or device not available | A capability is missing or misspelled, or the deviceName and platformVersion pair isn't offered. | Copy the exact device name and OS version from the Capabilities Generator. |
| The session connects but no device is allocated | The test points at the browser hub, hub.lambdatest.com. | Use https://mobile-hub.lambdatest.com/wd/hub. |
| The session ends in the middle of a run | No command arrived within idleTimeout, which defaults to 120 seconds. | Raise idleTimeout in LT:Options, for example to 300. |
Python rejects the desired_capabilities argument | Appium Python Client 3 and later removed it. | Build the driver with AppiumOptions, as in Step 3. |
The app can't reach localhost or staging | The cloud device can't see your private network. | Start the Tunnel and add "tunnel": true to LT:Options. |
For more errors and fixes, see troubleshooting Appium tests on TestMu AI.
FAQ
How do I run Appium tests on iOS with TestMu AI?
Upload your .ipa in Step 2. In Step 3, set platformName to ios, and set deviceName and platformVersion to an iPhone model and iOS version from the Capabilities Generator. In Java, use IOSDriver in place of AndroidDriver. The rest of the test stays the same.
Can I run Appium tests on emulators and simulators?
Yes. Upload the app to https://manual-api.lambdatest.com/app/upload/virtualDevice and set isRealMobile to false. For an iOS simulator, upload a .zip of the app instead of an .ipa. See app upload with the REST API.
Do I need a local Appium server?
No. Your test sends its commands to the TestMu AI mobile hub at mobile-hub.lambdatest.com, which runs the session on the cloud device. You only install the Appium client for your language.
Where do I find the capabilities for a specific device?
Use the Capabilities Generator to build a capability set for any device and OS version. Appium desired capabilities on TestMu AI lists every supported key.
How do I run tests on several devices at once?
Start one Appium session per device. Each device runs one automation session at a time, and your plan's concurrent session limit sets how many run in parallel. Tests above that limit wait in a queue. See queuing Appium tests.
Related Docs
- Set Appium desired capabilities for real devices
- Upload apps to the real device cloud
- Upload and manage apps with the REST API
- Troubleshoot Appium tests on TestMu AI
- Run Appium tests in your language and framework
- Read results in the App Automation Dashboard
- Test locally hosted apps with the Tunnel
- Appium testing tutorial
To test your app on real Android and iOS devices in the cloud, see the TestMu AI Real Device Cloud.