https://github.com/google/snippet-uiautomator
Mobly UiAutomator module for using Python code to operate UI actions on an Android device.
https://github.com/google/snippet-uiautomator
android google mobly python uiautomator
Last synced: 2 months ago
JSON representation
Mobly UiAutomator module for using Python code to operate UI actions on an Android device.
- Host: GitHub
- URL: https://github.com/google/snippet-uiautomator
- Owner: google
- License: apache-2.0
- Created: 2023-05-23T00:01:36.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-31T07:50:05.000Z (3 months ago)
- Last Synced: 2026-04-10T09:03:44.517Z (2 months ago)
- Topics: android, google, mobly, python, uiautomator
- Language: Java
- Homepage: https://github.com/google/snippet-uiautomator
- Size: 45.1 MB
- Stars: 49
- Watchers: 2
- Forks: 24
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Snippet UiAutomator
[](https://github.com/google/snippet-uiautomator/releases/latest)
[](https://github.com/google/snippet-uiautomator/actions)
[](https://github.com/google/snippet-uiautomator/actions)
This is the Python wrapper based on
[Mobly Snippet Lib](https://github.com/google/mobly-snippet-lib) for calling the
[AndroidX UiAutomator](https://developer.android.com/reference/androidx/test/uiautomator/package-summary)
APIs.
## Requirements
- Python 3.7+
- Android 8.0+ (SDK 26+)
## Installation
```shell
pip install snippet-uiautomator
```
### Initial Mobly Android Controller
- Inside Mobly Test
To use in a Mobly test, the Android device needs to be initialized in the
Mobly base test.
```python
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.
```python
from mobly.controllers import android_device
ad = android_device.AndroidDevice('GOOG1234567890')
```
To learn more about Mobly, visit
[Getting started with Mobly](https://github.com/google/mobly/blob/master/docs/tutorial.md).
### Launch UiAutomator Service
> [!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](https://github.com/google/mobly/blob/master/docs/android_device_service.md).
```python
from snippet_uiautomator import uiautomator
ad.services.register(
uiautomator.ANDROID_SERVICE_NAME, uiautomator.UiAutomatorService
)
ad.ui(text='OK').click()
```
## Test
Run unit tests for Python part:
```shell
pytest
```
Run tests for Snippet part:
```shell
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:
```shell
pip install pre-commit
pre-commit install
```
## API Usage
- [Configurator](https://github.com/google/snippet-uiautomator/blob/main/docs/configurator.md)
- [Selector](https://github.com/google/snippet-uiautomator/blob/main/docs/selector.md)
- [UiDevice](https://github.com/google/snippet-uiautomator/blob/main/docs/uidevice.md)
- [UiObject2](https://github.com/google/snippet-uiautomator/blob/main/docs/uiobject2.md)
- [UiWatcher](https://github.com/google/snippet-uiautomator/blob/main/docs/uiwatcher.md)