commit | b81439f425cf0efc4c69bfbcc90d09c7681bdb07 | [log] [tgz] |
---|---|---|
author | Kolin Lu <kolinlu@google.com> | Tue Sep 16 21:25:13 2025 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Tue Sep 16 21:30:51 2025 -0700 |
tree | 88b4842a7fbcbbe7ede0acf4e991f880b029f89a | |
parent | 72ba4dcccd1c6cf0fc37fb400801b9b8bdfb4ce5 [diff] |
Use Mobly new built-in apk_utils to install apk (#79) GitOrigin-RevId: e0a90d4af8e7bc6d1e0b5c59d48b80c6596a42be Change-Id: I0f93bf6192d76b0d4e10dca677d632ff83ef916e
This is the Python wrapper based on Mobly Snippet Lib for calling the AndroidX UiAutomator APIs.
pip install snippet-uiautomator
Inside Mobly Test
To use in a Mobly test, the Android device needs to be initialized in the Mobly base test.
from mobly import base_test from mobly.controllers import android_device class MoblyTest(base_test.BaseTestClass): def setup_class(self): ad = self.register_controller(android_device)[0]
Outside Mobly Test
If not using in a Mobly test, such as when running in a Python terminal, the Android device can be initialized with its serial number.
from mobly.controllers import android_device ad = android_device.AndroidDevice('GOOG1234567890')
To learn more about Mobly, visit Getting started with Mobly.
[!WARNING] UiAutomation is a service that can only be used by one app at a time. If this service is already being registered by another app, Snippet UiAutomator will not be able to start. To resolve this issue, stop the app holding the UiAutomation service before calling Snippet UiAutomator.
Snippet UiAutomator supports launching as one of Mobly Android Device Service.
from snippet_uiautomator import uiautomator ad.services.register( uiautomator.ANDROID_SERVICE_NAME, uiautomator.UiAutomatorService ) ad.ui(text='OK').click()
Run unit tests for Python part:
pytest
Run tests for Snippet part:
cd snippet_uiautomator/android ./gradlew test
Set up pre-commit hooks, this will run some automated checks during each git
commit and possibly update some files that require changes:
pip install pre-commit pre-commit install