patrol icon indicating copy to clipboard operation
patrol copied to clipboard

Native component AlertDialog.Builder for showing overlays over apps can't be found or interacted with patrol

Open aburtea opened this issue 7 months ago • 3 comments

Steps to reproduce

  1. Create a flutter application that triggers a native overlay using the AlertDialog.Builder. The dialog should have some text and some buttons (the draw over other apps Android permission is required) Eg of dialog creation:
val builder: AlertDialog.Builder = AlertDialog.Builder(contextThemeWrapper)
        builder.setView(contentView)
        builder.setOnDismissListener {
            onDismissListener.onDismiss(it)
        }

    fun createOverlayDialog(
        builder: AlertDialog.Builder,
    ): AlertDialog {
        val alertDialog: AlertDialog = builder.create()
        alertDialog.window?.setClipToOutline(true)
        alertDialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
        alertDialog.window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)

        return alertDialog
    }

alertDialog.show
  1. Make a patrol test that verify the overlay show and interact with overlay buttons

Actual results

I tried with "patrol.native.getNativeViews" but does not find the alert dialog view by id, nor by text . This works only on flutter components.

Note: Seems the patrol library can interact with system dialog views for permissions under the hud. We are expecting to have a method exposed that can interact with the overlay dialogs created by the app, by knowing the actual custom view components ids that are used for creating the overlay dialog content.

Logs

"patrol.native.getNativeViews" returns null. "await $('Click me!').tap();" does nothing for the button that has "Click me!" text in the overlay dialog.

Patrol version

patrol_cli: v3.5.1

Patrol Doctor output

Patrol doctor: Patrol CLI version: 3.5.1 Flutter command: flutter Flutter 3.29.3 • channel stable Android: • Program adb found in /Users//Library/Android/sdk/platform-tools/adb • Env var $ANDROID_HOME set to /Users//Library/Android/sdk iOS / macOS: • Program xcodebuild found in /usr/bin/xcodebuild • Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller

Flutter Doctor output

╰─$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.29.3, on macOS 15.4.1 24E263 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 16.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2024.2) [✓] VS Code (version 1.100.0) [✓] Connected device (5 available) ! Error: Browsing on the local area network for Iphone - . Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources

• No issues found!

aburtea avatar May 15 '25 08:05 aburtea

Hi @aburtea. Have you also tried using patrol devtools to inspect the view in patrol develop mode? Is the overlay also not reflected in that view tree?

piotruela avatar May 21 '25 07:05 piotruela

Hello! I try to run my test and use this Flutter DevTools Extension while I run it, but nothing is visible in the tree, same for run my app in debug mode until the overlay screen is visible but nothing in the tree and also same for "adb shell uiautomator dump" command to obtain views from that overlay, but nothing in the window_dump.xml generd by the command

aburtea avatar May 21 '25 13:05 aburtea

"await $('Click me!').tap();" does nothing for the button that has "Click me!" text in the overlay dialog. Hi @aburtea did you try await $.native.tap(Selector(text: 'Click me'));? Example that you mention will not work on the native side.

Kendru98 avatar Jul 09 '25 06:07 Kendru98