Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6d7e56e

Browse files
author
Nurhan Turgut
committed
addressing reviewer comments
1 parent 181c9d1 commit 6d7e56e

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

e2etests/web/regular_integration_tests/README.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,31 @@ More details for "Running Flutter Driver tests with Web" can be found in [wiki](
4040

4141
## Adding screenshot tests
4242

43-
In order to test screenshot tests the tests on the driver side needs to call the `integration_test` package with an `onScreenshot` callback which can do a comparison between the `screenshotBytes` taken during the test and a golden file. We added a utility method that can do this comparison by using a golden in `flutter/goldens` repository. In order to use screenshot testing follow these steps:
43+
In order to test screenshot tests the tests on the driver side needs to call the `integration_test` package with an `onScreenshot` callback which can do a comparison between the `screenshotBytes` taken during the test and a golden file. We added a utility method that can do this comparison by using a golden in `flutter/goldens` repository.
4444

45-
1. Call `screenshot_support.dart` from the driver side test (example: text_editing_integration_test.dart). Default value for `diffRateFailure` is 0.5 .
45+
In order to use screenshot testing first, import `screenshot_support.dart` from the driver side test (example: `text_editing_integration_test.dart`). Default value for `diffRateFailure` is 0.5.
4646

4747
```
4848
import 'package:regular_integration_tests/screenshot_support.dart' as test;
4949
5050
Future<void> main() async {
5151
final double kMaxDiffRateFailure = 0.1;
52-
await test.runTestWithScreenshots(diffRateFailure = kMaxDiffRateFailure );
52+
await test.runTestWithScreenshots(diffRateFailure = kMaxDiffRateFailure);
5353
}
5454
```
5555

56-
2. In order to add the screenshot golden initially or to update the existing one, we need to set UPDATE_GOLDENS flag to environment.
56+
In order to run the tests follow these steps:
5757

58-
```
59-
export UPDATE_GOLDENS=true
60-
```
61-
62-
3. Run the specific test or run all integration tests
58+
1. You can use two different approaches, using [felt](https://github.com/flutter/engine/blob/master/lib/web_ui/dev/README.md) tool will run all the tests, an update all the goldens. For running individual tests, we need to set UPDATE_GOLDENS environment variable.
6359

6460
```
65-
flutter drive -v --target=test_driver/text_editing_integration.dart -d web-server --release --local-engine=host_debug_unopt
61+
felt test --integration-tests-only --update-screenshot-goldens
6662
```
6763

6864
```
69-
felt test --integration-tests-only
65+
UPDATE_GOLDENS=true flutter drive -v --target=test_driver/text_editing_integration.dart -d web-server --release --local-engine=host_debug_unopt
7066
```
7167

72-
4. The golden will be under `engine/src/flutter/lib/web_ui/.dart_tool/goldens/engine/web/` directory, you should create a PR for that file and merge it to `flutter/goldens`.
73-
74-
5. Get the commit no and replace the `revision` in this file: `engine/src/flutter/lib/web_ui/dev/goldens_lock.yaml`
75-
76-
6. Don't forget to rechange the flag to switch goldens from update mode to comparison mode.
77-
78-
79-
```
80-
export UPDATE_GOLDENS=false
81-
```
68+
2. The golden will be under `engine/src/flutter/lib/web_ui/.dart_tool/goldens/engine/web/` directory, you should create a PR for that file and merge it to `flutter/goldens`.
8269

83-
7. Screenshot tests should work after this.
70+
3. Get the commit SHA and replace the `revision` in this file: `engine/src/flutter/lib/web_ui/dev/goldens_lock.yaml`

e2etests/web/regular_integration_tests/lib/screenshot_support.dart

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import 'package:image/image.dart';
2222
/// under test ex: a blinking cursor.
2323
const double kMaxDiffRateFailure = 0.5 / 100; // 0.5%
2424

25-
const int kMaxScreenshotWidth = 1024;
26-
const int kMaxScreenshotHeight = 1024;
25+
/// SBrowser screen dimensions for the Flutter Driver test.
26+
const int _kScreenshotWidth = 1024;
27+
const int _kScreenshotHeight = 1024;
2728

2829
/// Used for calling `integration_test` package.
2930
///
@@ -38,8 +39,8 @@ const int kMaxScreenshotHeight = 1024;
3839
/// It also includes options for updating the golden files.
3940
Future<void> runTestWithScreenshots(
4041
{double diffRateFailure = kMaxDiffRateFailure,
41-
int browserWidth = kMaxScreenshotWidth,
42-
int browserHeight = kMaxScreenshotHeight}) async {
42+
int browserWidth = _kScreenshotWidth,
43+
int browserHeight = _kScreenshotHeight}) async {
4344
final WebFlutterDriver driver =
4445
await FlutterDriver.connect() as WebFlutterDriver;
4546

@@ -50,16 +51,20 @@ Future<void> runTestWithScreenshots(
5051
window.setSize(Rectangle<int>(0, 0, browserWidth, browserHeight));
5152

5253
bool updateGoldens = false;
54+
// We are using an environment variable instead of an argument, since
55+
// this code is not invoked from the shell but from the `flutter drive`
56+
// tool itself. Therefore we do not have control on the command line
57+
// arguments.
58+
// Please read the README, further info on how to update the goldens.
5359
final String updateGoldensFlag = io.Platform.environment['UPDATE_GOLDENS'];
54-
if (updateGoldensFlag == null || updateGoldensFlag.toLowerCase() != 'true') {
55-
// We are using an environment variable since instead of an argument, since
56-
// this code is not invoked from the shell but from the `flutter drive`
57-
// tool itself. Therefore we do not have control on the command line
58-
// arguments.
59-
// Please read the README, further info on how to update the goldens.
60-
print('INFO: Goldens will not be updated. Please set `UPDATE_GOLDENS` '
61-
'environment variable to `true` for updating them.');
62-
} else {
60+
// Validate if the environment variable is set correctly.
61+
if (updateGoldensFlag != null &&
62+
!(updateGoldensFlag.toLowerCase() == 'true' ||
63+
updateGoldensFlag.toLowerCase() == 'false')) {
64+
throw StateError(
65+
'UPDATE_GOLDENS environment variable is not set correctly');
66+
}
67+
if (updateGoldensFlag != null && updateGoldensFlag.toLowerCase() == 'true') {
6368
updateGoldens = true;
6469
}
6570

@@ -77,10 +82,12 @@ Future<void> runTestWithScreenshots(
7782
forIntegrationTests: true,
7883
write: updateGoldens,
7984
);
80-
if (result != 'OK') {
81-
print('ERROR: $result');
85+
if (result == 'OK') {
86+
return true;
87+
} else {
88+
io.stderr.writeln('ERROR: $result');
89+
return false;
8290
}
83-
return result == 'OK';
8491
} else {
8592
return true;
8693
}

lib/web_ui/dev/goldens_lock.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
repository: https://github.com/nturgut/goldens.git
2-
revision: 6163d4e5970d739a413886c7b16136f2c8baf351
1+
repository: https://github.com/flutter/goldens.git
2+
revision: 7b9c0fa3b69bcea1501975268e8afa64f07cb313

lib/web_ui/dev/integration_tests_manager.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class IntegrationTestsManager {
2424

2525
final DriverManager _driverManager;
2626

27-
IntegrationTestsManager(this._browser, this._useSystemFlutter)
27+
final bool _doUpdateScreenshotGoldens;
28+
29+
IntegrationTestsManager(
30+
this._browser, this._useSystemFlutter, this._doUpdateScreenshotGoldens)
2831
: _driverManager = DriverManager.chooseDriver(_browser);
2932

3033
Future<bool> runTests() async {
@@ -159,14 +162,19 @@ class IntegrationTestsManager {
159162

160163
Future<bool> _runTestsInProfileMode(
161164
io.Directory directory, String testName) async {
162-
final String executable =
165+
String executable =
163166
_useSystemFlutter ? 'flutter' : environment.flutterCommand.path;
167+
Map<String, String> enviroment = Map<String, String>();
168+
if (_doUpdateScreenshotGoldens) {
169+
enviroment['UPDATE_GOLDENS'] = 'true';
170+
}
164171
final IntegrationArguments arguments =
165172
IntegrationArguments.fromBrowser(_browser);
166173
final int exitCode = await runProcess(
167174
executable,
168175
arguments.getTestArguments(testName, 'profile'),
169176
workingDirectory: directory.path,
177+
environment: enviroment,
170178
);
171179

172180
if (exitCode != 0) {

lib/web_ui/dev/test_runner.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ class TestCommand extends Command<bool> with ArgUtils {
159159

160160
Future<bool> runIntegrationTests() async {
161161
await _prepare();
162-
return IntegrationTestsManager(browser, useSystemFlutter).runTests();
162+
return IntegrationTestsManager(
163+
browser, useSystemFlutter, doUpdateScreenshotGoldens)
164+
.runTests();
163165
}
164166

165167
Future<bool> runUnitTests() async {

0 commit comments

Comments
 (0)