-
Notifications
You must be signed in to change notification settings - Fork 27.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[integration_test] Plugin not registered unless running via XCTest #91668
Comments
Hi @tritao, Thanks for filing the issue. I can reproduce the issue on the latest stable and the master channel. logsMaster
Stable 2.5.2
|
I am also having this same issue. Here is my code Flutter Doctor: |
Hi there,
Error logs
flutter doctor -v
Is there anyway to workaround this one? |
I posted a workaround in the initial post. |
hi @maheshmnj I wonder when we can have the plan to fix this issue? |
@ductranit, Please check the wiki to understand how the issues are prioritized. |
Can confirm the issue as well as the fix, thanks! |
I can also confirm that editing flutter/packages/integration_test/ios/Classes/IntegrationTestPlugin.m and then running |
I have the issue as well and it is a blocker, because I want to generate screenshots in CodeMagic as well. /offtopic: @tritao I thought https://github.com/mmcc007/screenshots uses a deprecated test API. Are you using it with integration_tests? I thought the package is also 2 years old? Would love if you could share some resources in regards of this. @bwaide I'm testing CodeMagic as well, could you share some resources how to trigger tests in CodeMagic and how to upload those screenshots to the App Store backends? |
We are also running into this issue. Hope it gets fixed soon. |
You can check out the version I am using at https://github.com/tritao/screenshots/commits/integration_test_latest |
@tritao Thanks for linking and maintaining it. Would it be possible to publish the After doing some research I figured out that integration_tests are limited in a sense that I have to run them for each device type in sequence whereas traditional flutter tests run on the host and thus are capable of spawning several AVDs/Simulators to do all the screenshots for all device types in one go. Since your fork is using integration_tests I wonder how you would implement generating screenshots for all devices within any CI/CD workflow, like on codemagic. May I ask if you fully automate screenshot generation with it, or so you manually run your tests? |
Thank you @tritao , could you please provide a sample of how the pubspec.yaml would look in order to use the version you posted. Currenly mine look like this.
|
So is the current approach to integration testing in flutter, that if you want to capture a screenshot, that you need to change/edit the source to Flutter SDK so that the Flutter supplied integration_test_driver_extended drivers work and actually do what the code was supposed to do - so is the "extended" driver currently outside Flutter's own testing program? How ironic that the testing tools aren't properly being tested... LOL... sorry for the light hearted comments here, but I just wanted to make sure that I've not missed another path to testing integration with Flutter. |
Yep this is painful for and Flutter iOS first app 😭 |
@ductranit Where do we make this change/work around? |
@workerbee22 it's in |
Taking screenshots for testing is very common. Hopefully, this fix will be merged soon! |
This is still present in flutter 3. Anyone trying to follow the instructions at https://github.com/flutter/flutter/blob/main/packages/integration_test/README.md on iOS hits this issue. |
Despite testing being a Flutter team goal for Y22 there seems to be little effort being directed here... so I've found the traditional test driver to work fine. YMMV |
cc: @jmagman |
This comment was marked as duplicate.
This comment was marked as duplicate.
Hey everyone, here's a quick script using the solution above that you can add to your pipeline. You should be able to run this anywhere:
To rollback, simply go to your Flutter's folder and run |
@jmagman I was able to reproduce this in the following versions: |
A slight improvement to make it work with the symlink brew uses, and not to add it again if its already been run...
|
I agree with others that this is a problem, and also agree that it's unfortunate that I cannot run an integration test from VS Code and have it work as expected on iOS. There is a workaround that doesn't involve patching the SDK and allows integration with CI/CD for iOS again, but it requires some changes to your app code and minor changes to your testing code.
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class Screenshotable extends StatefulWidget {
Screenshotable({
required this.child,
super.key,
});
final Widget child;
@override
ScreenshotableState createState() => ScreenshotableState();
}
class ScreenshotableState extends State<Screenshotable> {
final GlobalKey _renderKey = GlobalKey();
/// Captures the image from the current widget. This will return `null` if
/// the image cannot be captured for any reason.
Future<Uint8List?> captureImage() async {
Uint8List? image;
try {
var boundary = _renderKey.currentContext!.findRenderObject()
as RenderRepaintBoundary?;
if (boundary != null &&
(!kDebugMode || boundary.debugNeedsPaint != true)) {
var mq = MediaQuery.of(context);
var img = await boundary.toImage(pixelRatio: mq.devicePixelRatio);
var byteData = await img.toByteData(
format: ui.ImageByteFormat.png,
);
image = byteData?.buffer.asUint8List();
}
} catch (e) {
// no-op; ignore it because screenshots may not always be supported
}
return image?.isEmpty == true ? null : image;
}
@override
Widget build(BuildContext context) => RepaintBoundary(
key: _renderKey,
child: widget.child,
);
}
runApp(
(!kIsWeb && Platform.isIOS)
? MaterialApp( // This provides the MediaQuery
home: Screenshotable(
child: MyApp(),
),
)
: MyApp(),
);
@override
Future<Uint8List> takeScreenshot() async {
Uint8List? image;
try {
if (!kIsWeb && Platform.isIOS) {
try {
var ss = find.byType(Screenshotable).evaluate().first as StatefulElement;
await tester.pump();
image = await (ss.state as ScreenshotableState).captureImage();
} catch (e) {
_logger.info('Screenshot failed', e);
}
} else {
try {
if (!kIsWeb && Platform.isAndroid) {
await binding.convertFlutterSurfaceToImage();
}
} catch (e) {
// no-op
}
await tester.pump();
image = Uint8List.fromList(await binding.takeScreenshot('screenshot'));
}
} catch (e) {
_logger.info('Screenshot failed', e);
}
return image;
} |
This comment was marked as duplicate.
This comment was marked as duplicate.
I think if you follow the guidelines for the device testing on iOS it should work fine for you. For the guys who still want this fix, here's the simplest workaround without changing the plugin directly, you can call the @UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
IntegrationTestPlugin.instance().setupChannels(controller.binaryMessenger)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
} The code works fine for my test case. |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
I wasn't able to get the originally reported stuck runloop from #48601 to reproduce, even when I totally reverted flutter/plugins#2465. I also validated flutter/plugins#2514 passes when it's reverted. Talked to @gaaclarke and we suspect some precondition for the original bug have been resolved... somewhere. This code was moved from flutter/plugins to the SDK, making bisecting this tricky, and probably not worth it if I can't reproduce it from Xcode or the command line at all with either a static or dynamic linked integration_test. So let's try re-adding the |
…gin issue on iOS Links: - flutter/flutter#91668 (comment)
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 |
So as the title says, the integration_test native plugin is not being correctly registered unless running tests via XCTest, like when running via
flutter drive
.This unfortunately breaks use cases like automatic taking screenshots via https://github.com/mmcc007/screenshots for instance.
I've tracked the issue down to a fix in flutter/plugins#2465.
Changing
IntegrationTestPlugin.m:registerWithRegistrar
to the code below fixes the issue and seems to make things work, but I am assuming might bring back the XCTest init issue the PR tried to fix originally.@gaaclarke, can you take a look / any idea on what should be done here?
Steps to Reproduce
flutter drive --target=integration_test/main_test.dart --driver=test_driver/integration_test.dart
Expected results:
Actual results:
Code sample
Logs
The text was updated successfully, but these errors were encountered: