If you haven’t installed Patrol yet, start with the main installation guide.
Prerequisites
Before setting up native automation, ensure you have:Platform-Specific Setup
Native automation requires integration with native test frameworks. Choose your platform:- Android
- iOS
- Web
Android Setup
Native automation on Android uses UiAutomator through Patrol’s custom test runner.Create MainActivityTest.java
Create
android/app/src/androidTest/java/com/example/myapp/MainActivityTest.java:MainActivityTest.java
If your AndroidManifest.xml uses
android:name="io.flutter.embedding.android.FlutterActivity",
replace MainActivity.class with io.flutter.embedding.android.FlutterActivity.class.Configure build.gradle.kts
Edit
android/app/build.gradle.kts and add to defaultConfig:android/app/build.gradle.kts
Groovy Build Files
If your project uses Groovy (.gradle files instead of .gradle.kts):android/app/build.gradle
Configuration Options
Native Automator Config
You can customize native automation behavior in your tests:patrol_test/example_test.dart
Keyboard Behavior
Control how the keyboard is handled when entering text:Troubleshooting
Android
ClassNotFoundException: PatrolJUnitRunner
ClassNotFoundException: PatrolJUnitRunner
Ensure you’ve added
patrol to your pubspec.yaml dev_dependencies and run:Tests not found
Tests not found
Verify your
patrol_test directory exists and contains .dart test files.ProGuard errors
ProGuard errors
Disable ProGuard for debug builds or configure keep rules for Patrol classes.
iOS
Module 'patrol' not found
Module 'patrol' not found
Ensure you ran
pod install in the ios directory after updating Podfile.Tests run in parallel and fail
Tests run in parallel and fail
Disable parallel execution in all Xcode schemes (Edit Scheme > Test > uncheck “Execute in parallel”).
Build phase errors
Build phase errors
Verify the xcode_backend scripts are in the correct order and User Script Sandboxing is disabled.
Web
Node.js not found
Node.js not found
Install Node.js from nodejs.org or use a version manager like nvm.
Browser driver issues
Browser driver issues
Let Patrol install drivers automatically on first run, or manually run:
Next Steps
Usage Guide
Learn how to use the native automation API
Write Your First Test
Create your first Patrol test with native automation


