@@ -16,7 +16,7 @@ import 'package:image/image.dart';
1616///
1717/// We are allowing a higher difference rate compared to the unit tests (where
1818/// this rate is set to 0.28), since during the end to end tests there are
19- /// more components on the screen which are not related to the functinality
19+ /// more components on the screen which are not related to the functionality
2020/// under test ex: a blinking cursor.
2121const double kMaxDiffRateFailure = 0.5 / 100 ; // 0.5%
2222
@@ -31,29 +31,26 @@ const double kMaxDiffRateFailure = 0.5 / 100; // 0.5%
3131///
3232/// It provides an `onScreenshot` callback to the `integrationDriver` method.
3333/// It also includes options for updating the golden files.
34- Future <void > main () async {
34+ Future <void > runTestWithScreenshots (
35+ {double diffRateFailure = kMaxDiffRateFailure}) async {
3536 final WebFlutterDriver driver =
3637 await FlutterDriver .connect () as WebFlutterDriver ;
3738
3839 // Learn the browser in use from the webDriver.
3940 final String browser = driver.webDriver.capabilities['browserName' ] as String ;
4041
4142 bool updateGoldens = false ;
42- try {
43+ final String updateGoldensFlag = io.Platform .environment['UPDATE_GOLDENS' ];
44+ if (updateGoldensFlag == null || updateGoldensFlag.toLowerCase () != 'true' ) {
4345 // We are using an environment variable since instead of an argument, since
4446 // this code is not invoked from the shell but from the `flutter drive`
4547 // tool itself. Therefore we do not have control on the command line
4648 // arguments.
4749 // Please read the README, further info on how to update the goldens.
48- updateGoldens =
49- io.Platform .environment['UPDATE_GOLDENS' ].toLowerCase () == 'true' ;
50- } catch (ex) {
51- if (ex
52- .toString ()
53- .contains ('is not a subtype of type \' bool\' in type cast' )) {
54- print ('INFO: goldens will not be updated, please set `UPDATE_GOLDENS` '
55- 'environment variable to true' );
56- }
50+ print ('INFO: Goldens will not be updated. Please set `UPDATE_GOLDENS` '
51+ 'environment variable to `true` for updating them.' );
52+ } else {
53+ updateGoldens = true ;
5754 }
5855
5956 test.integrationDriver (
@@ -65,7 +62,7 @@ Future<void> main() async {
6562 updateGoldens,
6663 '$screenshotName -$browser .png' ,
6764 PixelComparison .fuzzy,
68- kMaxDiffRateFailure ,
65+ diffRateFailure ,
6966 forIntegrationTests: true ,
7067 write: updateGoldens,
7168 );
0 commit comments