Why Migrate?
The new Platform Automation API offers:- Unified API: Single, consistent interface across all platforms
- Web Support: Test Flutter web applications alongside mobile
- Better Organization: Clear separation between cross-platform and platform-specific actions
- Type Safety: Improved type checking and better IDE support
- Future-Proof: Active development and long-term support
Understanding the New API Structure
The Platform Automation API is organized into clear namespaces:In most cases, you’ll use
$.platform.mobile for cross-platform mobile automation.Breaking Changes You’ll Likely Hit
Here are the most common changes you’ll need to make:Entry Point Changes
Selector Changes
Quick Migration Checklist
Follow this checklist to ensure complete migration:Rename Test Directory (Optional)
Rename Or configure to keep using
integration_test/ to patrol_test/ and update .gitignore:integration_test/:pubspec.yaml
Update Native Automation Calls
Replace all deprecated API calls:
$.native.*→$.platform.mobile.*or platform-specific$.native2.*→$.platform.mobile.*
Update Selector Types
Replace:
NativeSelector(...)→MobileSelector(...),Selector(...), orPlatformSelector(...)
Common Migration Patterns
Pressing Home Button
Platform-Specific Actions
Some actions are platform-specific and need the appropriate namespace:Understanding Selector Types
Patrol 4.0 actions accept different selector types depending on the context. Here’s when to use each:Selector(...) - Universal Selector
Use when the same selector works across all platforms (most common for text-based selectors):
Selector is the simplest and most portable option. Use it whenever possible.MobileSelector(...) - Mobile-Only Selector
Use when Android and iOS require different selectors:
This is the direct replacement for
NativeSelector from Patrol 3.x.PlatformSelector(...) - Cross-Platform Selector
Use with the platform router ($.platform.tap) to support Android, iOS, and Web:
PlatformSelector can also be used with $.platform.mobile.* methods as long as it includes both Android and iOS selectors.Detailed Migration Examples
Example 1: Permission Dialogs
Example 2: Notifications
Example 3: Device Settings
Example 4: Custom Automator with Teardown
Configuration Migration
If you’re using custom automator configuration:Search and Replace Guide
Use these patterns for bulk migration:| Find | Replace |
|---|---|
$.native.tap( | $.platform.mobile.tap( |
$.native. | $.platform.mobile. (review each for platform-specific) |
$.native2. | $.platform.mobile. |
NativeSelector( | MobileSelector( |
NativeAutomator( | PlatformAutomator( |
NativeAutomatorConfig( | PlatformAutomatorConfig.fromOptions( |
Platform-Specific Actions Reference
Android-Only Actions
These actions should use$.platform.android.*:
iOS-Only Actions
These actions should use$.platform.ios.*:
Cross-Platform Mobile Actions
These actions work on both Android and iOS using$.platform.mobile.*:
Testing Web Applications
With Patrol 4.0, you can now test web applications:Learn more about web testing in the Web Testing Guide.
Troubleshooting
”Method not found” Errors
If you see errors about methods not being found:- Check you’re using the correct namespace (
mobile,android,ios, orweb) - Verify the method exists in Patrol 4.0 (some may have been renamed)
- Ensure you’ve updated to the latest Patrol version
Type Errors with Selectors
If you get type errors with selectors:Platform-Specific Action on Wrong Platform
If Android-specific actions fail on iOS (or vice versa):Migration Validation
After migration, verify your tests work correctly:Check for Deprecation Warnings
Review test output for any deprecation warnings and update those usages.
Benefits of the New API
After migration, you’ll benefit from:- Clearer code: Explicit platform namespaces make intent obvious
- Better errors: Improved error messages when actions fail
- Web support: Ability to test Flutter web applications
- Type safety: Stronger typing catches errors at compile time
- Future features: New capabilities will be added to the Platform API
Need Help?
If you encounter issues during migration:- Review the v3 to v4 migration guide for version-specific changes
- Check the platform automation documentation
- Visit our GitHub repository for issues
- Join our Discord community for support
Next Steps
After completing the migration:- Explore web testing capabilities
- Learn about platform automation features
- Review effective Patrol patterns
- Try the VS Code Extension