Native automation

Overview

Flutter's integration_test does a good job at providing basic support for integration testing Flutter apps. What it can't do is interaction with the OS your Flutter app is running on. This makes it impossible to test many critical business features:

  • granting runtime permissions
  • signing into the app which uses WebView or OAuth (like Google) as the login page
  • listing and tapping on notifications
  • exiting the app, coming back, and verifying that state is preserved
  • enabling and disabling features such as Wi-Fi, mobile data, location, or dark mode

Patrol's platform automation feature finally solves these problems. Here's a tiny snippet to spice things up:

patrol_test/demo_test.dart
void main() {
  patrolTest('demo', (PatrolIntegrationTester $) async {
    await $.pumpWidgetAndSettle(AwesomeApp());
    // prepare network conditions
    await $.platform.mobile.enableCellular();
    await $.platform.mobile.disableWifi();

    // toggle system theme
    await $.platform.mobile.enableDarkMode();

    // handle native location permission request dialog
    await $.platform.mobile.selectFineLocation();
    await $.platform.mobile.grantPermissionWhenInUse();

    // tap on the first notification
    await $.platform.mobile.openNotifications();
    await $.platform.mobile.tapOnNotificationByIndex(0);
  });
}

For web applications, Patrol provides browser-specific automation capabilities. You can interact with browser dialogs, manage cookies, handle file uploads, and more:

patrol_test/web_demo_test.dart
void main() {
  patrolTest('web demo', (PatrolIntegrationTester $) async {
    await $.pumpWidgetAndSettle(AwesomeWebApp());

    // grant browser permissions
    await $.platform.web.grantPermissions(permissions: ['clipboard-read']);

    // manage cookies
    await $.platform.web.addCookie(name: 'session', value: 'abc123');

    // handle browser dialogs
    await $.platform.web.acceptNextDialog();
  });
}
Platform automation is currently available on Android, iOS, and Web.
View post on X
View post on X