Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix screenshot testing for flutter web integration_test #117114

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

Merged
merged 10 commits into from
Dec 22, 2022

Conversation

kenzieschmoll
Copy link
Member

@kenzieschmoll kenzieschmoll commented Dec 14, 2022

Fixes #117077.

A complete example of screenshot testing still needs to be provided. This is better to be done once the screenshot testing workflow for integration tests is better thought out for web. Issue tracked at #86120.

@flutter-dashboard flutter-dashboard bot added the f: integration_test The flutter/packages/integration_test plugin label Dec 14, 2022
@kenzieschmoll kenzieschmoll marked this pull request as ready for review December 15, 2022 21:32
@kenzieschmoll
Copy link
Member Author

@yjbanov @Piinks This is ready for review. Please let me know what needs to be changed, and Kate, Yegor mentioned you might be able to help me move this PR over to using Skia Gold instead of the manual .png storage I have done here. Eager to get the changes to package:integration_test landed so we can use them in DevTools 👍 Thanks!

@Piinks
Copy link
Contributor

Piinks commented Dec 15, 2022

Yegor mentioned you might be able to help me move this PR over to using Skia Gold

Yeah, we can't check image files into this repo. Unfortunately, I can't set up integration tests to send images to Gold right now.

Someone did wire them up for tests in exmaples/api though, you may be able to use #99298 as a guide. :)

@kenzieschmoll
Copy link
Member Author

@Piinks do you know of any usages of flutter_goldens in integration tests?

@kenzieschmoll
Copy link
Member Author

I followed the pattern in #99298 and added this to the test:

    await expectLater(
      find.byType(MaterialApp),
      matchesGoldenFile('platform_name.png'),
    );

When running the test:
flutter drive --driver=test_driver/extended_integration_test.dart --target=integration_test/extended_test.dart -d chrome

this is what was output:
Golden comparison requested for "platform_name.png"; skipping...

List<int> screenshotBytes, [
Map<String, Object?>? args,
]) async {
// Here is an example of what updating a golden image might look like.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yjbanov @Piinks would it be acceptable to land this PR with the provided example in comments so that .png's are never added to this example? This still give some guidance or inspiration into how someone could hook up golden image testing if they weren't able to use Skia Gold.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally, I can also remove this example and just leave the changes in this PR that are outside the example/ directory. We will do something like this for DevTools, since it looks like Skia Gold has not been hooked up yet for web integration tests (#86120). I'd like to unblock screenshot testing in integration tests for DevTools (even without skia gold support), so let me know what you think. Thanks.

@Piinks
Copy link
Contributor

Piinks commented Dec 16, 2022

I followed the pattern in #99298 and added this to the test:

    await expectLater(
      find.byType(MaterialApp),
      matchesGoldenFile('platform_name.png'),
    );

When running the test: flutter drive --driver=test_driver/extended_integration_test.dart --target=integration_test/extended_test.dart -d chrome

this is what was output: Golden comparison requested for "platform_name.png"; skipping...

Did you push those changes? It won't work locally, it needs to be authenticated in CI.

@kenzieschmoll
Copy link
Member Author

Did you push those changes? It won't work locally, it needs to be authenticated in CI.

Ah okay. Pushed them up now, so we'll see if it worked 👍

@yjbanov
Copy link
Contributor

yjbanov commented Dec 19, 2022

I'm not sure if flutter_goldens will work on the web. flutter test sets up a local server that knows how to take screenshots and compare them. I'm not aware of flutter drive or package:integration_test attempting to do that. package:integration_test wants us to perform the comparison in the onScreenshot callback, which is not part of the test code. We may need to look for something we can use in the callback. My first intuition was to use SkiaClient directly.

Alternatively, we can keep it simple for now and instead of integrating with Skia Gold, use package:image to decode the PNG and spot check a few pixels.

@kenzieschmoll
Copy link
Member Author

Alternatively, we can keep it simple for now and instead of integrating with Skia Gold, use package:image to decode the PNG and spot check a few pixels.

Isn't the problem that we can't check PNGs into the codebase? how would we be able to use package:image to compare images without checking goldens in?

@yjbanov
Copy link
Contributor

yjbanov commented Dec 19, 2022

Isn't the problem that we can't check PNGs into the codebase? how would we be able to use package:image to compare images without checking goldens in?

Sorry, by "PNG" I meant the screenshot that the test takes and passes to the onScreenshot callback as screenshotBytes. The callback could parse the screenshot image and check a few known pixels in it.

@kenzieschmoll
Copy link
Member Author

The callback could parse the screenshot image and check a few known pixels in it.

How would we get the "known" pixels? This sounds a bit hand wavy. Would we expect the average flutter developer to know how to parse out image "hot spots" from byte code and store those as constants to compare the new screenshotBytes to? Whatever is here in this example is likely the resource that users will look at to figure out how to add screenshot testing through package:integration_test to their app.

Could we possibly separate this PR into two tasks:

  1. land the changes to packages/integration_test/lib (which un-breaks screenshot testing for flutter web and makes the onScreenshot handler more flexible)
  2. Add an up to date example to the onScreenshot callback in examples/ on how to actually do the image comparison? It may make more sense to do this once a formal support for flutter_goldens on the web or some other recommended way is decided upon. For projects that are not Flutter, keeping .pngs in a repo and comparing the bytes may be a fine solution. Please see my question here: Fix screenshot testing for flutter web integration_test #117114 (comment).

I would like to shift this PR to address task 1 and leave task 2 for a later day when this user journey is better addressed.

@flutter-dashboard flutter-dashboard bot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Dec 21, 2022
@kenzieschmoll
Copy link
Member Author

kenzieschmoll commented Dec 21, 2022

#117496 contains the same changes to dev/test.dart that this PR does (the changes to add the formerly failing tests in integration_test/example to Linux_web_long_running_tests on the CI). #117496 demonstrates that these tests are failing at master, but passing in this PR after the changes contained here.

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kenzieschmoll kenzieschmoll added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 22, 2022
@auto-submit auto-submit bot merged commit 725c141 into flutter:master Dec 22, 2022
@kenzieschmoll kenzieschmoll deleted the integration-test branch December 22, 2022 22:00
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 23, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Dec 23, 2022
auto-submit bot pushed a commit to flutter/plugins that referenced this pull request Dec 23, 2022
* 95ff839 Roll Plugins from 54fc206 to 2dd85ec (3 revisions) (flutter/flutter#117535)

* b8d5d9c Revert "Remove single-view assumption from widgets library (#117480)" (flutter/flutter#117545)

* bd482eb fixes android_semantics_integration_test to expect long press for tooltip (flutter/flutter#117547)

* 725c141 Fix screenshot testing for flutter web integration_test (flutter/flutter#117114)

* 999356b Remove single-view assumption from ScrollPhysics (flutter/flutter#117503)

* 6eb002a Reland "Remove single-view assumption from widgets library (#117480)" (flutter/flutter#117549)

* 08209b7 Explain how to test onSubmitted in its docs (flutter/flutter#117550)

* 20bc2ba Roll Flutter Engine from a90c45db3f13 to 234ab4c1e9c4 (1 revision) (flutter/flutter#117555)

* abd5217 Bump ossf/scorecard-action from 2.1.1 to 2.1.2 (flutter/flutter#117554)

* 6781576 Reland iOS 16 context menu (flutter/flutter#117234)

* daa2ecf Roll Flutter Engine from 234ab4c1e9c4 to ca0c843bf75f (11 revisions) (flutter/flutter#117563)

* 6441a7d Roll Flutter Engine from ca0c843bf75f to 12badb54598d (2 revisions) (flutter/flutter#117566)

* a0cecbe 3b5fb86a5 delete unused lib/src/engine/canvaskit/viewport_metrics.dart (flutter/engine#38474) (flutter/flutter#117572)

* fbfda23 Roll Flutter Engine from 3b5fb86a5982 to 6295d9198da1 (3 revisions) (flutter/flutter#117576)

* 3eca29b f2a071692 Roll Skia from 3e39affa3e1d to 45466d04ca49 (1 revision) (flutter/engine#38480) (flutter/flutter#117579)

* 05914e7 948d0bffa Roll Dart SDK from 47f192463696 to 442614a6c1bb (1 revision) (flutter/engine#38481) (flutter/flutter#117581)

* a34dec2 00995b7b9 Roll Skia from 45466d04ca49 to e206aa0c44f0 (4 revisions) (flutter/engine#38482) (flutter/flutter#117585)

* 4ef24cf 238f40bb9 Roll Fuchsia Mac SDK from W0GUdjHi4gI48optN... to 9w7QDlttR9f7Gu7U6... (flutter/engine#38483) (flutter/flutter#117587)

* a45a2f3 ad042d863 Roll Skia from e206aa0c44f0 to a8b7ce3b6391 (1 revision) (flutter/engine#38484) (flutter/flutter#117589)
tarrinneal pushed a commit to flutter/packages that referenced this pull request Dec 27, 2022
* 95ff839 Roll Plugins from 54fc206 to 2dd85ec (3 revisions) (flutter/flutter#117535)

* b8d5d9c Revert "Remove single-view assumption from widgets library (#117480)" (flutter/flutter#117545)

* bd482eb fixes android_semantics_integration_test to expect long press for tooltip (flutter/flutter#117547)

* 725c141 Fix screenshot testing for flutter web integration_test (flutter/flutter#117114)

* 999356b Remove single-view assumption from ScrollPhysics (flutter/flutter#117503)

* 6eb002a Reland "Remove single-view assumption from widgets library (#117480)" (flutter/flutter#117549)

* 08209b7 Explain how to test onSubmitted in its docs (flutter/flutter#117550)

* 20bc2ba Roll Flutter Engine from a90c45db3f13 to 234ab4c1e9c4 (1 revision) (flutter/flutter#117555)

* abd5217 Bump ossf/scorecard-action from 2.1.1 to 2.1.2 (flutter/flutter#117554)

* 6781576 Reland iOS 16 context menu (flutter/flutter#117234)

* daa2ecf Roll Flutter Engine from 234ab4c1e9c4 to ca0c843bf75f (11 revisions) (flutter/flutter#117563)

* 6441a7d Roll Flutter Engine from ca0c843bf75f to 12badb54598d (2 revisions) (flutter/flutter#117566)

* a0cecbe 3b5fb86a5 delete unused lib/src/engine/canvaskit/viewport_metrics.dart (flutter/engine#38474) (flutter/flutter#117572)

* fbfda23 Roll Flutter Engine from 3b5fb86a5982 to 6295d9198da1 (3 revisions) (flutter/flutter#117576)

* 3eca29b f2a071692 Roll Skia from 3e39affa3e1d to 45466d04ca49 (1 revision) (flutter/engine#38480) (flutter/flutter#117579)

* 05914e7 948d0bffa Roll Dart SDK from 47f192463696 to 442614a6c1bb (1 revision) (flutter/engine#38481) (flutter/flutter#117581)

* a34dec2 00995b7b9 Roll Skia from 45466d04ca49 to e206aa0c44f0 (4 revisions) (flutter/engine#38482) (flutter/flutter#117585)

* 4ef24cf 238f40bb9 Roll Fuchsia Mac SDK from W0GUdjHi4gI48optN... to 9w7QDlttR9f7Gu7U6... (flutter/engine#38483) (flutter/flutter#117587)

* a45a2f3 ad042d863 Roll Skia from e206aa0c44f0 to a8b7ce3b6391 (1 revision) (flutter/engine#38484) (flutter/flutter#117589)
loic-sharma pushed a commit to fluttergithubbot/flutter that referenced this pull request Jan 6, 2023
* Fix screenshot testing for flutter web integration_test

* update packages

* fix method signature and todo

* Run tests on CI

* fix type

* remove silences

* Add docs

* fix comment

* fix whitespace

* review comments
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jan 19, 2023
* Fix screenshot testing for flutter web integration_test

* update packages

* fix method signature and todo

* Run tests on CI

* fix type

* remove silences

* Add docs

* fix comment

* fix whitespace

* review comments
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
* 95ff839 Roll Plugins from 54fc206 to 2dd85ec (3 revisions) (flutter/flutter#117535)

* b8d5d9c Revert "Remove single-view assumption from widgets library (#117480)" (flutter/flutter#117545)

* bd482eb fixes android_semantics_integration_test to expect long press for tooltip (flutter/flutter#117547)

* 725c141 Fix screenshot testing for flutter web integration_test (flutter/flutter#117114)

* 999356b Remove single-view assumption from ScrollPhysics (flutter/flutter#117503)

* 6eb002a Reland "Remove single-view assumption from widgets library (#117480)" (flutter/flutter#117549)

* 08209b7 Explain how to test onSubmitted in its docs (flutter/flutter#117550)

* 20bc2ba Roll Flutter Engine from a90c45db3f13 to 234ab4c1e9c4 (1 revision) (flutter/flutter#117555)

* abd5217 Bump ossf/scorecard-action from 2.1.1 to 2.1.2 (flutter/flutter#117554)

* 6781576 Reland iOS 16 context menu (flutter/flutter#117234)

* daa2ecf Roll Flutter Engine from 234ab4c1e9c4 to ca0c843bf75f (11 revisions) (flutter/flutter#117563)

* 6441a7d Roll Flutter Engine from ca0c843bf75f to 12badb54598d (2 revisions) (flutter/flutter#117566)

* a0cecbe 3b5fb86a5 delete unused lib/src/engine/canvaskit/viewport_metrics.dart (flutter/engine#38474) (flutter/flutter#117572)

* fbfda23 Roll Flutter Engine from 3b5fb86a5982 to 6295d9198da1 (3 revisions) (flutter/flutter#117576)

* 3eca29b f2a071692 Roll Skia from 3e39affa3e1d to 45466d04ca49 (1 revision) (flutter/engine#38480) (flutter/flutter#117579)

* 05914e7 948d0bffa Roll Dart SDK from 47f192463696 to 442614a6c1bb (1 revision) (flutter/engine#38481) (flutter/flutter#117581)

* a34dec2 00995b7b9 Roll Skia from 45466d04ca49 to e206aa0c44f0 (4 revisions) (flutter/engine#38482) (flutter/flutter#117585)

* 4ef24cf 238f40bb9 Roll Fuchsia Mac SDK from W0GUdjHi4gI48optN... to 9w7QDlttR9f7Gu7U6... (flutter/engine#38483) (flutter/flutter#117587)

* a45a2f3 ad042d863 Roll Skia from e206aa0c44f0 to a8b7ce3b6391 (1 revision) (flutter/engine#38484) (flutter/flutter#117589)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App c: contributor-productivity Team-specific productivity, code health, technical debt. f: integration_test The flutter/packages/integration_test plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

package:integration_test screenshot testing is broken for flutter web
3 participants