Back to blog

How to Handle Native OS Permission Dialogs, WebViews, and Biometrics in Flutter with Patrol

Written by Kajal · Reviewed and published by Prasandeep

Published 6 min readTest Automation
How to Handle Native OS Permission Dialogs, WebViews, and Biometrics in Flutter with Patrol

Flutter integration tests handle buttons and text inside your app well. When the OS shows a permission popup, a WebView login page, or a Face ID / fingerprint prompt, those tests usually stop. They cannot see or touch anything outside the Flutter tree.

Patrol (open source from LeanCode) lets your Dart test code talk to the phone’s operating system. One language, native UI included.

This guide covers the three most common outside-Flutter cases—permission dialogs, WebViews, and biometrics—with patterns you can copy into real suites. For how mobile sits in a wider strategy, see Modern Test Pyramid 2026. For running mobile flows on device clouds, see BrowserStack vs LambdaTest vs Sauce Labs 2026.

What Patrol adds (one mental model)

Think of a Flutter-only test as a driver who can only operate inside the car. A permission dialog or Face ID prompt is the traffic officer outside. The driver cannot talk to them.

Patrol adds a small native helper on the device. Your Dart test sends commands over a local connection. Those commands run through:

So the same Dart file can grant a permission, type into a WebView, and (with setup) interact with a biometric prompt—without switching to Appium or a second language for the happy path.

Prerequisites

You need:

  • A Flutter app with Patrol set up (Patrol docs)
  • An emulator/simulator or a real device
  • For biometrics: enrolled Face ID / fingerprint on that device or emulator
  • Reasonable timeouts—native dialogs and WebViews are slower than pure Flutter widgets

Use patrol develop while writing tests. Hot restart is much faster than a full rebuild every change.

1. Native OS permission dialogs

The problem

When the app asks for camera, location, or notifications, the phone shows a system popup (“Allow”, “While Using the App”, “Only This Time”, “Don’t Allow”). That popup belongs to Android or iOS, not to your Flutter tree. A normal Flutter finder never sees it.

How Patrol helps

Patrol exposes simple mobile helpers, for example:

GoalTypical API
Is a permission dialog on screen?$.platform.mobile.isPermissionDialogVisible()
Allow / While Using$.platform.mobile.grantPermissionWhenInUse()
Only this time (Android 11+)$.platform.mobile.grantPermissionOnlyThisTime()
Deny$.platform.mobile.denyPermission()
Location accuracyselectFineLocation() / selectCoarseLocation()

Safe pattern

Always check visibility first. If the permission was already granted (common after a local hot restart), calling grant alone often fails.

Dart
await $('Request Location').tap(); if (await $.platform.mobile.isPermissionDialogVisible( timeout: const Duration(seconds: 5), )) { await $.platform.mobile.selectFineLocation(); await $.platform.mobile.grantPermissionWhenInUse(); await $.pump(); // let the Flutter UI react }

Practical details that save hours

  • CI usually installs fresh → permissions are not granted yet. That is ideal for permission tests.
  • Local runs often already have the permission → the dialog never appears. Guard with isPermissionDialogVisible.
  • iOS language: automatic handling works best when the device language is English (US). For other languages, fall back to tapping the button by visible text.
  • After granting, call await $.pump() or pumpAndSettle() so your Flutter UI updates.

2. WebViews

The problem

Many apps open a WebView for Google/Facebook login, custom OAuth, payments, or terms of service. The content is HTML, not Flutter widgets. Regular Flutter finders cannot reach it.

How Patrol helps

Because Patrol rides UiAutomator / XCUITest, it can see and interact with WebView content the same way it sees native buttons.

Dart
await $('Open Login WebView').tap(); await $.pump(const Duration(seconds: 4)); // WebViews need time to load await $.platform.mobile.tap(Selector(text: 'Sign in with Google')); await $.platform.mobile.enterText( Selector(text: 'Email'), 'test@example.com', );

Techniques that stay stable

  • Prefer Selector(text: ...), textContains, or platform selectors such as AndroidSelector(resourceName: ...) and IOSSelector(label: ...).
  • Treat cookie banners and consent dialogs the same way—they are often native or WebView buttons.
  • Wait explicitly. WebViews load asynchronously. Prefer wait-until-visible helpers over fixed sleeps when your Patrol version supports them; use short pumps only as a fallback.
  • For hard cases, inspect the native view hierarchy with Patrol’s DevTools extension and copy a stable selector.

This is how real authentication journeys become automatable in Flutter instead of being mocked forever.

3. Biometrics (Face ID, Touch ID, fingerprint)

The problem

Biometric prompts are pure OS UI. They also depend on hardware and enrollment. A normal Flutter test cannot “scan a fingerprint” or “look at the camera.”

What Patrol can and cannot do

Patrol does not ship a single magic authenticateWithFaceId() API. You combine device setup with native interaction:

Emulators / simulators (best for most CI)

  • Android Emulator: enroll a fingerprint in emulator settings, then use the emulator’s fingerprint simulation.
  • iOS Simulator: enroll Face ID / Touch ID under Features, then trigger a matching face.

Once enrolled, many local_auth prompts succeed automatically, or they become tappable native dialogs Patrol can hit.

Real devices

  • Pre-enroll biometrics on the test handset.
  • Treat the prompt as a native dialog and tap the positive control when the OS exposes one.
  • Some prompts are fully system-controlled and harder to automate. Teams often keep a small set of physical devices with known biometrics for those flows—or use a device cloud that supports biometric injection (see the cloud comparison linked above).

Practical pattern

Dart
await $('Unlock with Biometrics').tap(); await $.pump(const Duration(seconds: 2)); try { // Exact text varies by OS version and locale await $.platform.mobile.tap(Selector(textContains: 'Allow')); } catch (_) { // Many emulators succeed from enrolled biometrics with no extra tap } await $.pumpAndSettle(); expect($('Welcome, User'), findsOneWidget);

Reality check

Biometrics are still the hardest of the three. The reliable approach for CI is:

  1. Emulators with pre-enrolled biometrics for the main suite
  2. A small set of critical biometric tests on real devices when the risk justifies it

Patrol’s edge is that it can at least see and touch the native prompt once it appears—something pure Flutter tests cannot do.

Putting it together

SurfacePure Flutter testWith Patrol
Permission dialogStuck / blindDetect + grant / deny
WebView loginCannot find HTML controlsTap / type via native selectors
Biometric promptCannot authenticatePossible with enrolled device + native taps

Under the hood it is still one Dart test file. The native helper is what crosses the Flutter boundary.

Tips for stable suites

  1. Always check if a dialog is visible before acting on it.
  2. Use timeouts that match reality—permissions and WebViews can be slow.
  3. Prefer semantic selectors (visible text, accessibility labels, test IDs) over positions.
  4. Reset app state / permissions between CI runs (fresh install is usually enough).
  5. After WebView navigation, wait for the target control—not only a fixed sleep.
  6. Decide early: emulators only, real devices only, or both for biometrics.
  7. Write with patrol develop so iteration stays fast.

Summary

Teams without Patrol often mock permission dialogs, WebView logins, and biometric unlocks—or leave them to manual passes.

Patrol keeps tests in Dart while reaching native OS UI. Permissions are the easiest win; WebViews need waits and stable selectors; biometrics need enrolled emulators or a small real-device set.

Use it when those flows carry release risk. Skip it when mocks are enough for your coverage goals.

ShareLinkedInPost on X

Get the next guide in your inbox

Weekly AI testing insights, templates, and tool notes — unsubscribe anytime.