Patrol provides comprehensive support for testing Flutter applications on Android devices and emulators. Built on top of Android’s UIAutomator framework, Patrol enables you to interact with both Flutter widgets and native Android UI elements.
// Tap on native Android viewsawait $.platform.android.tap( AndroidSelector(text: 'Accept'),);// Double tapawait $.platform.android.doubleTap( AndroidSelector(resourceId: 'com.example:id/button'),);// Tap at specific coordinatesawait $.platform.android.tapAt(x: 100, y: 200);// Enter text into native viewsawait $.platform.android.enterText( AndroidSelector(text: 'Enter email'), text: '[email protected]',);// Enter text by indexawait $.platform.android.enterTextByIndex('username', index: 0);await $.platform.android.enterTextByIndex('password', index: 1);
// Tap on notification by selectorawait $.platform.mobile.openNotifications();await $.platform.android.tapOnNotificationBySelector( AndroidSelector(textContains: 'New message'),);// Tap by indexawait $.platform.android.tapOnNotificationByIndex(0);
// Take a photo with cameraawait $.platform.android.takeCameraPhoto();// Pick image from galleryawait $.platform.android.pickImageFromGallery();// Pick multiple imagesawait $.platform.android.pickMultipleImagesFromGallery();
Use AndroidSelector to target native Android views:
// By textAndroidSelector(text: 'Submit')// By text containsAndroidSelector(textContains: 'Submit')// By text starts withAndroidSelector(textStartsWith: 'Sub')// By resource IDAndroidSelector(resourceId: 'com.example.myapp:id/submit_button')// By class nameAndroidSelector(className: 'android.widget.Button')// By content descriptionAndroidSelector(contentDescription: 'Submit button')// Combine multiple selectorsAndroidSelector( className: 'android.widget.EditText', instance: 1, // Second EditText)
# Check device connectionadb devices# If no devices listed, check:# 1. USB debugging is enabled# 2. USB cable is working (try a different one)# 3. Device is authorized (check device screen for authorization prompt)# Restart ADB server if neededadb kill-serveradb start-server