简体   繁体   English

Flutter integration_test - 截图

[英]Flutter integration_test - Making screenshot

Hey are there any possibilities to make a screenshot when using integration_test lib ( https://pub.dev/packages/integration_test ) for UI tests?嘿,在使用 integration_test lib ( https://pub.dev/packages/integration_test ) 进行 UI 测试时,是否有可能制作屏幕截图?

In flutter_driver it was bulid in method to take it.在 flutter_driver 中,它是采用方法构建的。 Here i coldn't find any.在这里我找不到任何东西。

I found an open issue on GitHub - https://github.com/flutter/flutter/issues/51890我在 GitHub - https://github.com/flutter/flutter/issues/51890上发现了一个未解决的问题

They are working on that capability.他们正在研究这种能力。

The flutter integration test example has the skeleton to perform screenshots flutter 集成测试示例具有执行屏幕截图的骨架

First create the driver for the integration test首先为集成测试创建驱动程序

//test_driver/foo_test.dart
import 'dart:io';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:integration_test/integration_test_driver_extended.dart';

Future<void> main() async {
  final FlutterDriver driver = await FlutterDriver.connect();
  await integrationDriver(
    driver: driver,
    onScreenshot: (String screenshotName, List<int> screenshotBytes) async {
      final File image =
          await File(screenshotName).create(recursive: true);
      image.writeAsBytesSync(screenshotBytes);
      return true;
    },
  );
}

Then in your test然后在你的测试中

//integration_test/bar_test.dart
void main() {
  final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
      as IntegrationTestWidgetsFlutterBinding;

  testWidgets('screenshot', (WidgetTester tester) async {
    await tester.pumpWidget(MyApp());
    await tester.pumpAndSettle();
    await binding.convertFlutterSurfaceToImage();
    await tester.pumpAndSettle();
    await binding.takeScreenshot('screenshots/screenshot.png');
  }
}

Then然后

flutter drive --driver=test_driver/foo_test.dart --target integration_test/bar_test.dart 

Note:笔记:

  • the screenshot is a png屏幕截图是png
  • You cannot save directly from the test without tweaks (explain the necessity of a driver)你不能在没有调整的情况下直接从测试中保存(解释驱动程序的必要性)

From Flutter version 2.5.0 you can take a screenshot by very simple way.从 Flutter 版本 2.5.0 开始,您可以通过非常简单的方式进行截图。 Here is manual about how to do it: https://dev.to/mjablecnik/take-screenshot-during-flutter-integration-tests-435k这是有关如何操作的手册: https://dev.to/mjablecnik/take-screenshot-during-flutter-integration-tests-435k

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将参数传递给flutter integration_test? - How to pass parameters into flutter integration_test? 使用integration_test包在flutter集成测试中设置语言环境 - Setting locale in flutter integration test using integration_test package 使用 Flutter 新的 integration_test 的示例集成测试? - Sample integration test with Flutter new integration_test? Flutter 集成测试调试同时使用 integration_test package - Flutter integration test debugging while using integration_test package Flutter / Dart package integration_test with Z37A6259CC0C1DAE299A7866489 安全 - Flutter / Dart package integration_test with null safety 如何与来自 flutter integration_test 的本机 UI 元素进行交互? - How to interact with native UI elements from flutter integration_test? flutter 集成测试使用新的 integration_test package 测试异常时出错 - Error for flutter integration test using the new integration_test package to test exceptions Flutter integration_test:如何通过长按 shift 键和鼠标拖动来自动选择多个小部件 - Flutter integration_test: How to automate multiple selection of widgets by long pressing shift key and mouse drag Flutter integration_test:无法输入 integer,将值加倍到 tester.enterText() 方法? - Flutter integration_test: Can't input integer, double values to tester.enterText() method? Flutter integration_test:如何模拟键盘操作以从 TextField() 中清除文本? - Flutter integration_test: How to simulate keyboard action to clear text from TextField()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM