This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
E2e screenshot tests2 #21383
Merged
Merged
E2e screenshot tests2 #21383
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fccba87
carrying code
749c992
more changes for carrying the code
76ee23c
rebase changes onto ios-screenshot tests
37f4b9e
adding screenshot capability to text_editing e2e test
d087a57
address some comments
c5f24c2
change enable flag for isUnitTestsScreenshotsAvailable
65be5fc
addressing the reviewer comments
30e9339
change the dependency for path
527e889
add to licencense file
c77326f
changing goldens commit no. the new commit has the screenshot goldens
d19632a
update readme file
68630e5
firefox tests needs LUCI changes
5b56dd4
change to release mode since screenshots were taken in release mode
0512275
change window size
63bd027
some argument changes
9d8cb2f
small comment change
34c4739
test the chrome linux tests again
6e29b42
use roboto font instead of default font
eca1c93
addressing reviewer comments
96e779b
change commit for goldens
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
96 changes: 96 additions & 0 deletions
96
e2etests/web/regular_integration_tests/lib/screenshot_support.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:io' as io; | ||
import 'dart:math'; | ||
|
||
import 'package:flutter_driver/flutter_driver.dart'; | ||
import 'package:integration_test/integration_test_driver_extended.dart' as test; | ||
|
||
import 'package:web_test_utils/goldens.dart'; | ||
import 'package:web_test_utils/image_compare.dart'; | ||
import 'package:webdriver/src/async/window.dart'; | ||
|
||
import 'package:image/image.dart'; | ||
|
||
/// Tolerable pixel difference ratio between the goldens and the screenshots. | ||
/// | ||
/// We are allowing a higher difference rate compared to the unit tests (where | ||
/// this rate is set to 0.28), since during the end to end tests there are | ||
/// more components on the screen which are not related to the functionality | ||
/// under test ex: a blinking cursor. | ||
const double kMaxDiffRateFailure = 0.5 / 100; // 0.5% | ||
|
||
/// SBrowser screen dimensions for the Flutter Driver test. | ||
const int _kScreenshotWidth = 1024; | ||
const int _kScreenshotHeight = 1024; | ||
|
||
/// Used for calling `integration_test` package. | ||
/// | ||
/// Compared to other similar classes which only included the following call: | ||
/// ``` | ||
/// Future<void> main() async => test.integrationDriver(); | ||
/// ``` | ||
/// | ||
/// this method is able to take screenshot. | ||
/// | ||
/// It provides an `onScreenshot` callback to the `integrationDriver` method. | ||
/// It also includes options for updating the golden files. | ||
Future<void> runTestWithScreenshots( | ||
{double diffRateFailure = kMaxDiffRateFailure, | ||
int browserWidth = _kScreenshotWidth, | ||
int browserHeight = _kScreenshotHeight}) async { | ||
final WebFlutterDriver driver = | ||
await FlutterDriver.connect() as WebFlutterDriver; | ||
|
||
// Learn the browser in use from the webDriver. | ||
final String browser = driver.webDriver.capabilities['browserName'] as String; | ||
nturgut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
final Window window = await driver.webDriver.window; | ||
window.setSize(Rectangle<int>(0, 0, browserWidth, browserHeight)); | ||
|
||
bool updateGoldens = false; | ||
// We are using an environment variable instead of an argument, since | ||
// this code is not invoked from the shell but from the `flutter drive` | ||
// tool itself. Therefore we do not have control on the command line | ||
// arguments. | ||
// Please read the README, further info on how to update the goldens. | ||
final String updateGoldensFlag = io.Platform.environment['UPDATE_GOLDENS']; | ||
nturgut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Validate if the environment variable is set correctly. | ||
if (updateGoldensFlag != null && | ||
!(updateGoldensFlag.toLowerCase() == 'true' || | ||
updateGoldensFlag.toLowerCase() == 'false')) { | ||
throw StateError( | ||
'UPDATE_GOLDENS environment variable is not set correctly'); | ||
} | ||
if (updateGoldensFlag != null && updateGoldensFlag.toLowerCase() == 'true') { | ||
updateGoldens = true; | ||
} | ||
|
||
test.integrationDriver( | ||
driver: driver, | ||
onScreenshot: (String screenshotName, List<int> screenshotBytes) async { | ||
if (browser == 'chrome') { | ||
final Image screenshot = decodePng(screenshotBytes); | ||
final String result = compareImage( | ||
screenshot, | ||
updateGoldens, | ||
'$screenshotName-$browser.png', | ||
PixelComparison.fuzzy, | ||
diffRateFailure, | ||
forIntegrationTests: true, | ||
write: updateGoldens, | ||
); | ||
if (result == 'OK') { | ||
return true; | ||
} else { | ||
io.stderr.writeln('ERROR: $result'); | ||
return false; | ||
} | ||
} else { | ||
return true; | ||
} | ||
}, | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
repository: https://github.com/flutter/goldens.git | ||
revision: 1a4722227af42c3f51450266016b1a07ae459e73 | ||
revision: da3fef0c0eb849dfbb14b09a088c5f7916677482 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.