commit | 6b705e2e420c0f18ff220e684abe7bd44d6b3453 | [log] [tgz] |
---|---|---|
author | Erick Mungai <erick.mbugua20@gmail.com> | Mon Apr 21 11:02:38 2025 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Mon Apr 21 11:08:20 2025 -0700 |
tree | e5f50664e7cf0dc87d62cff566453d532a2d3113 | |
parent | 424195f0c57cea6a050c1061021dd815b94f19c8 [diff] |
Correct the return type of objects matching the selector. (#72) * Correct the return type. Some properties e.g visibleCenter and visibleBounds are represented as Mappings not (bool, int, str). Trying to access child properties e.g visibleCenter['x'] thus results in type checking errors. * Add a mapping type. --------- Co-authored-by: Erick Mungai <erickmungai@google.com> GitOrigin-RevId: a415d3664db12691979c4b8e262bf1d156dc282a Change-Id: I6c854e503ff0db5471c8d5aecf0ea4d527d323ab
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