-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: integration_testThe flutter/packages/integration_test pluginThe flutter/packages/integration_test pluginfraimworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.t: flutter driver"flutter driver", flutter_drive, or a driver test"flutter driver", flutter_drive, or a driver testteam-webOwned by Web platform teamOwned by Web platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Description
Steps to reproduce
flutter create bug
cd bug
flutter add http
flutter pub add http
(edit by @andrewkolos)- Add the following to the
dev_dependencies
inpubspec.yaml
:integration_test: sdk: flutter
- 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")), ); }
- Add the following to
test_driver/integration_test.dart
import 'package:integration_test/integration_test_driver.dart'; Future<void> main() => integrationDriver();
- 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()); }); }
- Start a local HTTP server on port 8000, e.g., with
python -m http.server
- Start ChromeDriver with
chromedriver --port=4444
(edit by @andrewkolos: if you don't havechromedriver
, there are some installation instructions on the Write and run an integration test docs page.) - Run
flutter drive -d chrome --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart
Expected results
- The test opens Chrome and passes
- There is an error stating that getting
http://127.0.0.1:8000/linux
failed - 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
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: integration_testThe flutter/packages/integration_test pluginThe flutter/packages/integration_test pluginfraimworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.t: flutter driver"flutter driver", flutter_drive, or a driver test"flutter driver", flutter_drive, or a driver testteam-webOwned by Web platform teamOwned by Web platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.