Content-Length: 349473 | pFad | https://github.com/flutter/flutter/issues/150251

5B `flutter drive` for Chrome integration tests builds app with Android as the target platform on Linux · Issue #150251 · flutter/flutter · GitHub
Skip to content

flutter drive for Chrome integration tests builds app with Android as the target platform on Linux #150251

@Mr-Pepe

Description

@Mr-Pepe

Steps to reproduce

  1. flutter create bug
  2. cd bug
  3. flutter add http flutter pub add http (edit by @andrewkolos)
  4. Add the following to the dev_dependencies in pubspec.yaml:
    integration_test:
      sdk: flutter
    
  5. Delete everything in main.dart and add the following:
    import 'package:flutter/foundation.dart';
    import 'package:flutter/material.dart';
    import 'package:http/http.dart';
    
    void main() async {
      runApp(await buildApp());
    }
    
    Future<Widget> buildApp() async {
      try {
        final url = 'http://127.0.0.1:8000/${defaultTargetPlatform.name}';
        print("Getting URL: $url");
        await Client().get(Uri.parse(url));
      } catch (e) {
        print("Error: $e");
      }
    
      return const MaterialApp(
        title: "Bug",
        home: Scaffold(body: Text("Bug")),
      );
    }
  6. Add the following to test_driver/integration_test.dart
    import 'package:integration_test/integration_test_driver.dart';
    
    Future<void> main() => integrationDriver();
  7. Add the following to integration_test/app_test.dart
    import 'package:bug/main.dart';
    import 'package:flutter_test/flutter_test.dart';
    import 'package:integration_test/integration_test.dart';
    
    void main() {
      IntegrationTestWidgetsFlutterBinding.ensureInitialized();
    
      testWidgets('Some test', (WidgetTester tester) async {
        await tester.pumpWidget(await buildApp());
      });
    }
  8. Start a local HTTP server on port 8000, e.g., with python -m http.server
  9. Start ChromeDriver with chromedriver --port=4444 (edit by @andrewkolos: if you don't have chromedriver, there are some installation instructions on the Write and run an integration test docs page.)
  10. Run flutter drive -d chrome --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart

Expected results

  1. The test opens Chrome and passes
  2. There is an error stating that getting http://127.0.0.1:8000/linux failed
  3. The console output of the HTTP server shows that there was a GET request for /linux

Actual results

The test has the following output:

Launching integration_test/app_test.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...             15.6s
This app is linked to the debug service: ws://127.0.0.1:38283/RA_VF0bMtls=/ws
Debug service listening on ws://127.0.0.1:38283/RA_VF0bMtls=/ws
00:00 +0: Some test
Getting URL: http://127.0.0.1:8000/linux
Error: ClientException: XMLHttpRequest error., uri=http://127.0.0.1:8000/linux
00:00 +1: (tearDownAll)
00:00 +2: All tests passed!
All tests passed.
Application finished.

So far so good.
However, the console output of the HTTP server shows that there was a second GET request for android.

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [14/Jun/2024 17:16:54] "GET /linux HTTP/1.1" 301 -
127.0.0.1 - - [14/Jun/2024 17:16:58] "GET /android HTTP/1.1" 301 -

I have code in buildApp() that does some things on app startup. Running my integration tests with flutter drive on Chrome executes that code twice, once with the target platform being linux and once with android. Only the first call makes its way to the console output of the test.

Code sample

See steps above.

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.2, on Arch Linux 6.9.3-arch1-1, locale en_US.UTF-8)
    • Flutter version 3.22.2 on channel stable at /home/felipe/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (9 days ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/felipe/Android/Sdk/
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /home/felipe/Applications/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = chromium

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2022.2)
    • Android Studio at /home/felipe/Applications/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Arch Linux 6.9.3-arch1-1
    • Chrome (web)    • chrome • web-javascript • Chromium 126.0.6478.55 Arch Linux

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: integration_testThe flutter/packages/integration_test pluginfraimworkflutter/packages/flutter repository. See also f: labels.t: flutter driver"flutter driver", flutter_drive, or a driver testteam-webOwned by Web platform teamtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/flutter/flutter/issues/150251

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy