Android Devices
Appium Geckodriver supports automating Gecko-related software on Android, such as the Firefox
browser and other Gecko-based webviews. This functionality requires the geckodriver binary version
0.26.0 or later.
In addition to the standard driver configuration, Android tests have further requirements:
- Android SDK and
adbmust be installed on the host machine - Real Android devices must have USB debugging enabled
Once the prerequisites have been set up, you can start a session on an Android device by specifying
one or more Android-related options under the moz:firefoxOptions capability.
Examples¶
The following capability set can be used to launch the Firefox browser on the first running Android emulator:
{
"platformName": "mac",
"browserName": "firefox",
"appium:automationName": "Gecko",
"moz:firefoxOptions": {
"androidPackage": "org.mozilla.firefox",
"androidDeviceSerial": "emulator-5554"
}
}
Troubleshooting¶
Permission Denial for File Creation¶
When starting an Android session, geckodriver pushes a temporary Firefox profile to the device.
On Android 11+ emulators or non-rooted real devices with scoped storage restrictions, geckodriver
may fail to create or change permissions for profile directories under /sdcard/Android/data/<package>/files/test_root.
This can manifest with errors such as adb error: couldn't create file: Permission denied or
fchown() failed: Operation not permitted.
To work around this:
- Try setting the
appium:androidStoragecapability tointernal(for example/data/local/tmp/test_root) orappinstead ofsdcard - If
/sdcard/Android/data/<package>/files/test_rootdoes not exist yet on an emulator, pre-create it withadb shell mkdir -p /sdcard/Android/data/<package>/files/test_rootor use a standarduserdebug(non-Google Play) Android emulator image - Set
appium:verbositytotraceto inspect the exactadbhost commands executed bymozdevice
Connecting to an Existing Android App¶
Setting appium:noReset to true passes the --connect-existing
flag to geckodriver. The geckodriver binary does not support this flag in combination with
moz:firefoxOptions.androidPackage, and will reject session creation with the error
SessionNotCreatedError: Cannot connect to an existing Android App yet.
To work around this:
- Launch or restart the Android browser normally by omitting
appium:noReset(or setting it tofalse) - Explicitly forward the Marionette port (configurable via
appium:marionettePort) to the host first (adb forward tcp:2828 tcp:2828), then omitandroidPackagefrommoz:firefoxOptions