Repository navigation
Closed
Labels
a: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsfound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: invalidIssue is closed as not validIssue is closed as not valid
Description
Building a simple Flutter app based on simple_example.dart with a test fails. Test code:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:testing_webview_flutter/main.dart';
void main() {
testWidgets('Smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MaterialApp(home: WebViewExample()));
});
}Stack trace:
$ flutter test
00:06 +0: Smoke test
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following _CastError was thrown building Builder:
Null check operator used on a null value
The relevant error-causing widget was:
MaterialApp
MaterialApp:file:///Users/brettmorgan/Documents/flutter-projects/testing_webview_flutter/test/widget_test.dart:16:35
When the exception was thrown, this was the stack:
#0 new PlatformWebViewController (package:webview_flutter_platform_interface/src/platform_webview_controller.dart:25:33)
#1 new WebViewController.fromPlatformCreationParams (package:webview_flutter/src/webview_controller.dart:28:25)
#2 new WebViewController (package:webview_flutter/src/webview_controller.dart:20:14)
#3 _WebViewExampleState.initState (package:testing_webview_flutter/main.dart:27:18)
#4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5015:57)
#5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4853:5)
... Normal element mounting (275 frames)
#280 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3863:16)
#281 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6435:36)
#282 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6447:32)
... Normal element mounting (416 frames)
#698 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3863:16)
#699 Element.updateChild (package:flutter/src/widgets/framework.dart:3586:20)
#700 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1195:16)
#701 RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1172:5)
#702 RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1186:7)
#703 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#704 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:19)
#705 AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1191:19)
#706 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:378:5)
#707 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#708 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
#709 AutomatedTestWidgetsFlutterBinding.pump.<anonymous closure> (package:flutter_test/src/binding.dart:1057:9)
#712 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#713 AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:1043:27)
#714 WidgetTester.pumpWidget.<anonymous closure> (package:flutter_test/src/widget_tester.dart:554:22)
#717 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#718 WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:551:27)
#719 main.<anonymous closure> (file:///Users/brettmorgan/Documents/flutter-projects/testing_webview_flutter/test/widget_test.dart:16:18)
#720 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:171:29)
<asynchronous suspension>
<asynchronous suspension>
(elided 5 frames from dart:async and package:stack_trace)
════════════════════════════════════════════════════════════════════════════════════════════════════
00:06 +0 -1: Smoke test [E]
Test failed. See exception logs above.
The test description was: Smoke test
To run this test again: /Users/brettmorgan/flutter/bin/cache/dart-sdk/bin/dart test /Users/brettmorgan/Documents/flutter-projects/testing_webview_flutter/test/widget_test.dart -p vm --plain-name 'Smoke test'
00:06 +0 -1: Some tests failed.Flutter doctor
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.2 22D7750270d darwin-arm, locale en)
• Flutter version 3.3.10 on channel stable at /Users/brettmorgan/flutter
• Upstream repository https://github.com/flutter/flutter
• Framework revision 135454af32 (5 days ago), 2022-12-15 07:36:55 -0800
• Engine revision 3316dd8728
• Dart version 2.18.6
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/brettmorgan/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• 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 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Community Edition (version 2022.2.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 70.0.5
• Dart plugin version 222.4167.21
[✓] VS Code (version 1.74.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.54.0
[✓] Connected device (3 available)
• iPhone 14 Pro (mobile) • BBCB0062-6656-4250-BDE9-564287448DA4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-2
(simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.2 22D7750270d darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.124
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!Reacted by jeiea
Metadata
Metadata
Assignees
Labels
a: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsfound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: invalidIssue is closed as not validIssue is closed as not valid
Activity
darshankawar commentedon Dec 21, 2022
@domesticmouse Hi,
I get same behavior after running the test example you provided above, but if we add below to the file, then the smoke test runs successfully:
What do you think ?
domesticmouse commentedon Dec 21, 2022
It's a bug. This behaviour is breaking the codelab written by the original authors of the previous version of the plugin. The v3 plugin doesn't break this way. The provided additional code is a workaround.
For what it's worth, I'll be adding a note to the codelab saying the android version of the plugin is currently broken with a pointer to this bug report.
darshankawar commentedon Dec 21, 2022
Thanks for the feedback.
stable, master flutter doctor -v
stuartmorgan-g commentedon Dec 21, 2022
/cc @bparrishMines
bparrishMines commentedon Dec 21, 2022
This test is failing because in pre-4.0, the platform implementation was set to Android by default: https://github.com/flutter/plugins/blob/5f62d21ebe38a45ed03e206eb1456b33bdb0b22d/packages/webview_flutter/webview_flutter/lib/src/webview.dart#L120.
This plugin now uses auto platform registration and no longer sets a default platform implementation: https://docs.flutter.dev/development/packages-and-plugins/developing-packages#dart-platform-implementations
I was able to get this test to pass:
Now that auto platform registration is available and we want this to be the standard, I don't think we want to set the platform implementation in
webview_flutteranymore.@domesticmouse Could we update the codelab to use the
FakePlatformas explained by @darshankawar?Or we could consider providing a
TestPlatforminwebview_flutterthat a user could set toWebViewPlatform.instancemanually.stuartmorgan-g commentedon Dec 21, 2022
I'm generally not a fan of us maintaining test implementations of things as part of the public API, since it creates a whole new things to maintain and have "should this be included in the main package" discussions about as people want increasingly complex test objects. I'd rather people set up their own tests the way they want them.
stuartmorgan-g commentedon Jan 3, 2023
It's a bug in the codelab though; we should update the codelab. (Which codelab is this?)
The nature of major version updates to packages is that code written against older versions may not work without updates.
Because the internal implementation details that such a test implicitly relied on happened to work with v3 and earlier versions. Our plugin structure has evolved over the years, and writing non-integration tests that assume plugins will work is now something we explicitly tell people not to do because it will work even less often than it used to.
It's not a workaround, it's following our current documented best practices. (Even better would be not including the plugin at all in any app-level tests, as described in the page above.)
domesticmouse commentedon Jan 5, 2023
The codelab that I was maintaining when I crafted this bug report was Adding WebView to your Flutter app . I have an updated version sitting in cl/496865324 waiting on an LGTM from @craiglabenz
The codelab itself doesn't contain any references to testing, but I had tests alongside the the code to make sure it worked to some level.
Okiday.
github-actions commentedon Mar 4, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.