Add a FlutterDriver screenshot test to device lab.#45411
Add a FlutterDriver screenshot test to device lab.#45411cyanglaz merged 3 commits intoflutter:masterfrom
Conversation
6fb0c78 to
18b0319
Compare
|
Looks like bots are unhappy |
|
Bots are still unhappy. |
1b579a7 to
7cba69d
Compare
|
@tvolkert It's green now! (except the flutter-build tree) |
| required_agent_capabilities: ["mac/ios"] | ||
| timeout_in_minutes: 20 | ||
|
|
||
| flutter_driver_screenshot_test: |
There was a problem hiding this comment.
Let's call this flutter_driver_screenshot_test_ios
|
|
||
| tearDownAll(() => driver.close()); | ||
|
|
||
| group('image rendering ', () { |
There was a problem hiding this comment.
Nit: no need for a group if there's only 1 test.
| test('A page with an image screenshot', () async { | ||
|
|
||
| await driver.waitFor(find.byValueKey('image_page')); | ||
| final SerializableFinder imagePageListTile = |
There was a problem hiding this comment.
If you put this line first, then you can await driver.waitFor(imagePageListTile);
| DriverScreenShotTester( | ||
| {@required this.testName, | ||
| @required this.driver, | ||
| @required this.deviceModel}) |
There was a problem hiding this comment.
Nit: the formatting will be a little nicer if you put a trailing comma after deviceModel
| /// | ||
| /// All the parameters are required and must not be null. | ||
| // ignore: always_require_non_null_named_parameters | ||
| DriverScreenShotTester( |
| const String _kPathParent = 'test_driver/goldens/'; | ||
|
|
||
| /// The utility class that helps test cases to tests screenshots with a [FlutterDriver]. | ||
| class DriverScreenShotTester { |
| /// Constructs a [DriverScreenShotTester]. | ||
| /// | ||
| /// All the parameters are required and must not be null. | ||
| // ignore: always_require_non_null_named_parameters |
There was a problem hiding this comment.
This ignore should not be needed
| /// prior to this call. | ||
| Future<bool> compareScreenshots(List<int> screenshot) async { | ||
| final File file = File(_getImageFilePath()); | ||
| final List<int> matcher = file.readAsBytesSync(); |
There was a problem hiding this comment.
Might as well use the async version since you're already in an async method.
| /// `test_driver/goldens/<testName>/<deviceModel>.png` | ||
| /// | ||
| /// Can be used when recording the golden for the first time. | ||
| Future<void> saveScreenshot(List<int> screenshot) async { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
this is not used, removing
| required_agent_capabilities: ["mac/ios"] | ||
| timeout_in_minutes: 20 | ||
|
|
||
| flutter_driver_screenshot_test: |
| /// Constructs a [DriverScreenShotTester]. | ||
| /// | ||
| /// All the parameters are required and must not be null. | ||
| // ignore: always_require_non_null_named_parameters |
| const String _kPathParent = 'test_driver/goldens/'; | ||
|
|
||
| /// The utility class that helps test cases to tests screenshots with a [FlutterDriver]. | ||
| class DriverScreenShotTester { |
| /// | ||
| /// All the parameters are required and must not be null. | ||
| // ignore: always_require_non_null_named_parameters | ||
| DriverScreenShotTester( |
| DriverScreenShotTester( | ||
| {@required this.testName, | ||
| @required this.driver, | ||
| @required this.deviceModel}) |
| /// prior to this call. | ||
| Future<bool> compareScreenshots(List<int> screenshot) async { | ||
| final File file = File(_getImageFilePath()); | ||
| final List<int> matcher = file.readAsBytesSync(); |
| /// `test_driver/goldens/<testName>/<deviceModel>.png` | ||
| /// | ||
| /// Can be used when recording the golden for the first time. | ||
| Future<void> saveScreenshot(List<int> screenshot) async { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
this is not used, removing
|
|
||
| tearDownAll(() => driver.close()); | ||
|
|
||
| group('image rendering ', () { |
| test('A page with an image screenshot', () async { | ||
|
|
||
| await driver.waitFor(find.byValueKey('image_page')); | ||
| final SerializableFinder imagePageListTile = |
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.dartChecklist
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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?