Skip to content

Add a FlutterDriver screenshot test to device lab.#45411

Merged
cyanglaz merged 3 commits intoflutter:masterfrom
cyanglaz:screenshot_integration_tests
Dec 6, 2019
Merged

Add a FlutterDriver screenshot test to device lab.#45411
cyanglaz merged 3 commits intoflutter:masterfrom
cyanglaz:screenshot_integration_tests

Conversation

@cyanglaz
Copy link
Copy Markdown
Contributor

@cyanglaz cyanglaz commented Nov 22, 2019

Description

Created a new app under dev/integration_test, can be used to run screenshot tests with FlutterDriver. More details can be found in the README.md in this PR.

Also added the test to the device lab. We currently only add this test for mac/ios(iphone 6s). We can enable running this test on other devices later.

This test can be used to catch regressions like #45098

Related Issues

#45348

Tests

I added the following tests:

dev/devicelab/bin/tasks/flutter_driver_screenshot_test.dart

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Nov 22, 2019
@cyanglaz cyanglaz requested a review from tvolkert November 22, 2019 18:44
@cyanglaz cyanglaz force-pushed the screenshot_integration_tests branch from 6fb0c78 to 18b0319 Compare November 22, 2019 18:49
@tvolkert
Copy link
Copy Markdown
Contributor

Looks like bots are unhappy

@tvolkert
Copy link
Copy Markdown
Contributor

tvolkert commented Dec 2, 2019

Bots are still unhappy.

@cyanglaz cyanglaz force-pushed the screenshot_integration_tests branch from 1b579a7 to 7cba69d Compare December 2, 2019 19:38
@cyanglaz
Copy link
Copy Markdown
Contributor Author

cyanglaz commented Dec 2, 2019

@tvolkert It's green now! (except the flutter-build tree)

Comment thread dev/devicelab/manifest.yaml Outdated
required_agent_capabilities: ["mac/ios"]
timeout_in_minutes: 20

flutter_driver_screenshot_test:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's call this flutter_driver_screenshot_test_ios

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


tearDownAll(() => driver.close());

group('image rendering ', () {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: no need for a group if there's only 1 test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

test('A page with an image screenshot', () async {

await driver.waitFor(find.byValueKey('image_page'));
final SerializableFinder imagePageListTile =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you put this line first, then you can await driver.waitFor(imagePageListTile);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

DriverScreenShotTester(
{@required this.testName,
@required this.driver,
@required this.deviceModel})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: the formatting will be a little nicer if you put a trailing comma after deviceModel

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

///
/// All the parameters are required and must not be null.
// ignore: always_require_non_null_named_parameters
DriverScreenShotTester(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: this could be const

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

const String _kPathParent = 'test_driver/goldens/';

/// The utility class that helps test cases to tests screenshots with a [FlutterDriver].
class DriverScreenShotTester {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@immutable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

/// Constructs a [DriverScreenShotTester].
///
/// All the parameters are required and must not be null.
// ignore: always_require_non_null_named_parameters
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This ignore should not be needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

/// prior to this call.
Future<bool> compareScreenshots(List<int> screenshot) async {
final File file = File(_getImageFilePath());
final List<int> matcher = file.readAsBytesSync();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might as well use the async version since you're already in an async method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

/// `test_driver/goldens/<testName>/<deviceModel>.png`
///
/// Can be used when recording the golden for the first time.
Future<void> saveScreenshot(List<int> screenshot) async {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When is this used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not used. It serves as a utility method to save the golden when setting up the test for the first time.

So when we want to add another screenshot test case, we can use this to save the golden image.

Maybe there is a better way to set up golden in flutter driver test?

}

/// Check if the golden exists.
bool goldenExists() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is not used, removing

Copy link
Copy Markdown
Contributor Author

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

@tvolkert Thanks for the quick turnaround. The PR is updated with suggestions and I left one comment on the saveScreenshot.

Comment thread dev/devicelab/manifest.yaml Outdated
required_agent_capabilities: ["mac/ios"]
timeout_in_minutes: 20

flutter_driver_screenshot_test:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

/// Constructs a [DriverScreenShotTester].
///
/// All the parameters are required and must not be null.
// ignore: always_require_non_null_named_parameters
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

const String _kPathParent = 'test_driver/goldens/';

/// The utility class that helps test cases to tests screenshots with a [FlutterDriver].
class DriverScreenShotTester {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

///
/// All the parameters are required and must not be null.
// ignore: always_require_non_null_named_parameters
DriverScreenShotTester(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

DriverScreenShotTester(
{@required this.testName,
@required this.driver,
@required this.deviceModel})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

/// prior to this call.
Future<bool> compareScreenshots(List<int> screenshot) async {
final File file = File(_getImageFilePath());
final List<int> matcher = file.readAsBytesSync();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

/// `test_driver/goldens/<testName>/<deviceModel>.png`
///
/// Can be used when recording the golden for the first time.
Future<void> saveScreenshot(List<int> screenshot) async {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not used. It serves as a utility method to save the golden when setting up the test for the first time.

So when we want to add another screenshot test case, we can use this to save the golden image.

Maybe there is a better way to set up golden in flutter driver test?

}

/// Check if the golden exists.
bool goldenExists() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is not used, removing


tearDownAll(() => driver.close());

group('image rendering ', () {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

test('A page with an image screenshot', () async {

await driver.waitFor(find.byValueKey('image_page'));
final SerializableFinder imagePageListTile =
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Contributor

@tvolkert tvolkert left a comment

Choose a reason for hiding this comment

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

LGTM

@cyanglaz cyanglaz merged commit adec697 into flutter:master Dec 6, 2019
@cyanglaz cyanglaz deleted the screenshot_integration_tests branch December 6, 2019 22:17
cyanglaz pushed a commit that referenced this pull request Dec 6, 2019
jmagman added a commit that referenced this pull request Dec 7, 2019
cyanglaz pushed a commit to cyanglaz/flutter that referenced this pull request Dec 9, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants