Skip to content

[camera] Integration tests require user interaction #130987

Open

Description

@stuartmorgan-g

I'm currently having to exclude the camera and camera_android tests from the new emulator CI tests I'm bringing up, because when they run a system dialog pops up asking for camera permissions. When running locally, if I tap it in the emulator everything runs fine.

It looks like this is probably a regression from flutter/packages#4348, because we have code in test_driver/integration_test.dart in the camera packages that is clearly supposed to handle this, by running adb commands once the process starts. Some options I can think of, although there may well be others:

  • Teach the repo tooling to use flutter drive for specific packages that opt out of flutter test. This will regress us in a way though, since flutter drive logs warnings that we should be using flutter test, and it's not clear to me if drive will even continue to be supported for non-web.
  • Find an alternate solution to grant permissions. E.g., can we grant them before the app is even installed, perhaps as part of emulator creation, or a new pre-test-run-script option in the repo tooling? I don't know what adb allows in that regard.
  • Add functionality to flutter test to allow for this in some way if possible (e.g., by allowing a custom driver even though one isn't normally used).

I'll be disabling this test in the emulator CI bringup for now to avoid blocking the rest of that work, via a new script/configs/exclude_integration_android_emulator.yaml file. When this is fixed, the exclusion should be remove from that file.

/cc @bparrishMines since he's been looking at the way integration tests run, the drive vs test differences, etc.

Activity

  1. added
    a: tests"flutter test", flutter_test, or one of our tests
    c: contributor-productivityTeam-specific productivity, code health, technical debt.
    platform-androidAndroid applications specifically
    packageflutter/packages repository. See also p: labels.
    team-androidOwned by Android platform team
    on Jul 20, 2023
  2. added
    P2Important issues not at the top of the work list
    fyi-infraFor the attention of Infrastructure team
    and removed
    team-androidOwned by Android platform team
    on Aug 24, 2023
  3. reidbaker commented on Aug 24, 2023

    @reidbaker
    Contributor

    Infra-team I think this is a limitation after migrating to LUCI. The request would be to build a supported way to grant runtime permissions on android.

  4. added
    c: new featureNothing broken; request for a new capability
    and removed
    P2Important issues not at the top of the work list
    on Aug 24, 2023
  5. stuartmorgan-g commented on Aug 24, 2023

    @stuartmorgan-g
    ContributorAuthor

    This was actually due to the flutter drive -> flutter test migration, rather than the LUCI migration. (It's related to LUCI only in that the LUCI migration allowed us to even run emulator tests at all.)

  6. reidbaker commented on Aug 25, 2023

    @reidbaker
    Contributor

    Ah thank you for the more accurate description.

  7. removed
    fyi-infraFor the attention of Infrastructure team
    on Aug 31, 2023
  8. 5 remaining items

  9. added
    P1High-priority issues at the top of the work list
    triaged-androidTriaged by Android platform team
    on Oct 19, 2023
  10. gmackall commented on Oct 19, 2023

    @gmackall
    Member

    Related to #86295

  11. gmackall commented on Dec 20, 2023

    @gmackall
    Member

    Lowering the priority for now as these tests are run in our device testing (just not on emulator).

  12. added
    P2Important issues not at the top of the work list
    and removed
    P1High-priority issues at the top of the work list
    on Dec 20, 2023
  13. MarkOSullivan94 commented on Jan 26, 2024

    @MarkOSullivan94
    Contributor

    There is an adb command that would work for this: https://developer.android.com/training/permissions/requesting#test-grant-all.

    I wonder if it would make sense to make a flag that can be added to flutter test that passes -g to the adb command? Something like flutter test --grant-permissions?

    I wonder if there is a similar flag/notion for other platforms.

    Granting all permissions would be a sufficient workaround to prevent tests from failing due to the native permission dialog getting in the way 🤞

    I also tried out adding this code snippet

    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    if (Build.VERSION.SDK_INT >= 28) {
      instrumentation.getUiAutomation().grantRuntimePermission("io.flutter.plugins.cameraxexample", Manifest.permission.CAMERA);
      instrumentation.getUiAutomation().grantRuntimePermission("io.flutter.plugins.cameraxexample", Manifest.permission.RECORD_AUDIO);
    }
    

    to the integration_test FlutterTestRunner, and that also worked to grant permissions. Perhaps it would make sense to add a way to call that code snippet to the integration_test api.

    Something like this exposed in the integration_test API would be an improvement on what's available for developers to use 🙌

  14. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Apr 24, 2024
  15. flutter-triage-bot commented on Apr 24, 2024

    @flutter-triage-bot

    This issue is assigned to @gmackall but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  16. flutter-triage-bot commented on Jul 10, 2024

    @flutter-triage-bot

    This issue was assigned to @gmackall but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

  17. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsc: contributor-productivityTeam-specific productivity, code health, technical debt.c: new featureNothing broken; request for a new capabilityp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions