AndroidAutomator provides Android-specific methods for native UI automation. Access it through $.platform.android in your Patrol tests.
Accessing AndroidAutomator
Android-Specific Methods
System Navigation
Quickly double-presses the recent apps button.
Location Services
Enables location services on Android.Opens the location settings screen and toggles the switch. If location is already enabled, does nothing.
Disables location services on Android.Opens the location settings screen and toggles the switch.
Initialization
Initializes the Android native automator.Used internally to initialize
android.app.UiAutomation before Flutter tests start. This method is idempotent.Reference: Flutter Issue #129231Configures the Android automator with settings from
AndroidAutomatorConfig.Element Interaction
Tapping
Taps on a native Android UI element.Parameters:
selector- AndroidSelector to locate the elementtimeout- Max time to wait (defaults tofindTimeoutfrom config)
Double taps on a native element.Parameters:
selector- Element to taptimeout- Max wait timedelayBetweenTaps- Time between taps (default: 300ms)
Taps at specific screen coordinates.Location values must be in the 0-1 range (normalized coordinates).
Text Entry
Enters text into a native Android text field.The element must be an
EditText or AutoCompleteTextView.Parameters:selector- The text field to targettext- Text to enter (required)keyboardBehavior- How to handle the keyboardtimeout- Max wait timetapLocation- Where to tap before entering text
Enters text into the nth visible text field.Parameters:
text- Text to enterindex- Index of the text field (required)keyboardBehavior- Keyboard handlingtimeout- Max wait time
Gestures
Performs a swipe gesture.Parameters:
from- Starting point (0-1 range)to- Ending point (0-1 range)steps- Speed control (default: 12, one step = 5ms)enablePatrolLog- Whether to log action
Performs a back swipe gesture (left to right).Parameters:
dy- Vertical position (0-1 range, default: 0.5)
Simulates a pull-to-refresh gesture.Parameters:
from- Starting point (default: center)to- Ending point (default: bottom-center)steps- Gesture speed (default: 50)
Notification Handling
Taps on a notification by its index.Notification shade must be opened first with
openNotifications().Taps on a notification using a selector.
UI Inspection
Returns the native Android UI tree.If
selector is null, returns the entire UI tree.Waits until an element becomes visible.
Camera & Gallery
Takes and confirms a photo using the device camera.Parameters:
shutterButtonSelector- Custom shutter button selectordoneButtonSelector- Custom done button selectortimeout- Max wait time
Picks a single image from the gallery.
Picks multiple images from the gallery.
AndroidSelector
The selector class for locating Android UI elements:Examples
Usage Examples
Complete Login Flow
Handle System Settings
See Also
- PlatformAutomator - Cross-platform interface
- IOSAutomator - iOS-specific methods
- MobileAutomator - Shared mobile methods