Skip to content

Screenshot taken with LiveTestWidgetsFlutterBinding is truncated #66006

@jiahaog

Description

@jiahaog

Internal: b/168776765

When using LiveTestWidgetsFlutterBinding, screenshots of top level widgets are truncated.

Context: We're trying to support screenshot testing in g3 with package:integration_test, where the widgets binding inherits from LiveTestWidgetsFlutterBinding. The following is a minimal repro with just flutter test.

Steps to Reproduce

Run flutter test with the following test file:

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  LiveTestWidgetsFlutterBinding();
  testWidgets('goldens', (tester) async {
    await tester.pumpWidget(buildTestApp());
    await expectLater(
        find.byType(MaterialApp), matchesGoldenFile('screenshot.png'));
  });
}

Widget buildTestApp() {
  final app = MaterialApp(
    title: 'Test',
    home: Scaffold(
      appBar: AppBar(
        title: Text('Title'),
      ),
    ),
  );

  // screenshot is taken for _LiveTestRenderView#c6f40
  return app;

  // screenshot is taken for RenderRepaintBoundary#f72ed
  // return RepaintBoundary(child: app);
}

Expected behavior: Screenshot covers the full MaterialApp.

Similar to this image from AutomatedTestWidgetsFlutterBinding (with L5 commented out)

screenshot_automated_test_binding

Actual Image (which looks truncated)

screenshot_live_test_binding

When I added some instrumentation to the renderObject used for taking a screenshot at

return layer.toImage(renderObject.paintBounds);

The renderObject is a LiveTestRenderView: _LiveTestRenderView#c6f40.

Adding a RepaintBoundary around MaterialApp (the last second line of the snippet) fixes the issue.

LiveTestWidgetsFlutterBinding with RepaintBoundary Image

screenshot_live_test_binding_with_repaint_boundary

#12994 looks like it could be related. It is pretty unexpected that a RepaintBoundary is needed just for LiveTestWidgetsFlutterBinding, but not for the default AutomatedTestWidgetsFlutterBinding, so this could be a bug. With AutomatedTestWidgetsFlutterBinding, the renderObject used for the screenshot is RenderRepaintBoundary#1d14f.

Another thing I noticed is that if the following

: _paintMatrix = _getMatrix(size, window.devicePixelRatio, window),
is set to

_paintMatrix = _getMatrix(size, 1.0, window)

the correct bounds are used for the image, though this probably isn't the correct fix.

Doctor Output
[✓] Flutter (Channel master, 1.22.0-10.0.pre.39, on Mac OS X 10.15.3 19D76, locale en-US)
    • Flutter version 1.22.0-10.0.pre.39 at /Users/jiahaog/dev/flutter
    • Framework revision a8281e31af (2 weeks ago), 2020-09-01 10:57:59 -0700
    • Engine revision 165abef0a2
    • Dart version 2.10.0 (build 2.10.0-77.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc2)
    • Android SDK at /Users/jiahaog/Library/Android/sdk
    • Platform android-stable, build-tools 30.0.0-rc2
    • Java binary at: /Applications/Android Studio with Blaze.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C505
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio with Blaze.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 3.5 Preview.app/Contents
    • Flutter plugin version 33.4.2
    • Dart plugin version 183.5901
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.48.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.14.0

[✓] Connected device (3 available)
    • iPhone 11 (mobile) • 5D77C64F-14CB-4C4B-B47D-62443C8678ED • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
    • Web Server (web)   • web-server                           • web-javascript • Flutter Tools
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 85.0.4183.102

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testscustomer: googleVarious Google teamsframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions