Advanced
Standalone native automation#
By standalone native automation means creating and using NativeAutomator
directly, that is, without PatrolTester
(a.k.a "the dollar" – $
).
This is useful if, for any reason, you have to use Flutter's default testWidgets() function rather than Patrol's patrolTest().
integration_test/app_test.dart
Future<void> main() async {
final automator = NativeAutomator(
packageName: 'your.app.id.on.android',
bundleId: 'your.app.id.on.ios',
);
await automator.configure();
testWidgets(
'test description',
(WidgetTester tester) async {
await automator.pressHome();
// more test code
},
);
}
Running tests without patrol_cli#
If, for any reason, you don't want to use Patrol CLI, you can run the tests using native Android and iOS testing tools directly. This is what Patrol CLI does under the hood anyway.
Android
Execute the below Gradle command in your app's android
directory:
./gradlew :app:connectedDebugAndroidTest -Ptarget=$(pwd)/../integration_test/example_test.dart
iOS device
Execute these 2 commands in your app's ios
directory:
flutter build ios --config-only \
--target integration_test/example_test.dart \
--debug
xcodebuild test \
-workspace Runner.xcworkspace \
-scheme Runner \
-xcconfig Flutter/Debug.xcconfig \
-configuration Debug \
-sdk iphoneos -destination "platform=iOS,name=Barteks-iPhone" \
OTHER_SWIFT_FLAGS='$(inherited) -D PATROL_ENABLED'
Of course, replace the device name with the name of your device.
iOS Simulator
Execute these 2 commands in your app's ios
directory:
flutter build ios --config-only \
--target integration_test/example_test.dart \
--debug \
--simulator
xcodebuild test \
-workspace Runner.xcworkspace \
-scheme Runner \
-xcconfig Flutter/Debug.xcconfig \
-configuration Debug \
-sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 14" \
OTHER_SWIFT_FLAGS='$(inherited) -D PATROL_ENABLED'