From 6dd17961b56c168f46ff1d7a4ddf90b5d161215f Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:59:00 +0200 Subject: [PATCH] Fixed Android screenshots generator --- .../mocks/paid_features_mock.dart | 2 +- screenshots/generate_screenshots.dart | 85 ++++++++++--------- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/integration_test/mocks/paid_features_mock.dart b/integration_test/mocks/paid_features_mock.dart index 8d4a287..84c5090 100644 --- a/integration_test/mocks/paid_features_mock.dart +++ b/integration_test/mocks/paid_features_mock.dart @@ -46,7 +46,7 @@ class _MockIAPProvidersState extends State { storageService: mockIAPStorageService, child: FilmsProvider( storageService: mockIAPStorageService, - availableFilms: mockFilms, + availableFilms: widget.films ?? mockFilms, child: widget.child, ), ); diff --git a/screenshots/generate_screenshots.dart b/screenshots/generate_screenshots.dart index f767245..e48ec60 100644 --- a/screenshots/generate_screenshots.dart +++ b/screenshots/generate_screenshots.dart @@ -22,6 +22,8 @@ import '../integration_test/utils/widget_tester_actions.dart'; //https://stackoverflow.com/a/67186625/13167574 +const _mockFilm = Film('Ilford HP5+', 400); + /// Just a screenshot generator. No expectations here. void main() { final binding = IntegrationTestWidgetsFlutterBinding(); @@ -62,53 +64,60 @@ void main() { }); } + setUpAll(() async { + if (Platform.isAndroid) await binding.convertFlutterSurfaceToImage(); + }); + /// Generates several screenshots with the light theme - testWidgets( - 'Generate light theme screenshots', - (tester) async { - mockSharedPrefs(ThemeType.light, lightThemeColor); - await tester.pumpApplication(); + testWidgets('Generate light theme screenshots', (tester) async { + mockSharedPrefs(ThemeType.light, lightThemeColor); + await tester.pumpApplication( + films: [_mockFilm], + selectedFilm: _mockFilm, + ); - await tester.takePhoto(); - await tester.takeScreenshot(binding, 'light-metering_reflected'); + await tester.takePhoto(); + await tester.takeScreenshot(binding, 'light-metering_reflected'); - if (Platform.isAndroid) { - await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor)); - await tester.pumpAndSettle(); - await tester.toggleIncidentMetering(7.3); - await tester.takeScreenshot(binding, 'light-metering_incident'); - } - - await tester.openAnimatedPicker(); - await tester.takeScreenshot(binding, 'light-metering_iso_picker'); - - await tester.tapCancelButton(); - await tester.tap(find.byTooltip(S.current.tooltipOpenSettings)); + if (Platform.isAndroid) { + await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor)); await tester.pumpAndSettle(); - await tester.takeScreenshot(binding, 'light-settings'); - - await tester.tapDescendantTextOf(S.current.meteringScreenLayout); - await tester.takeScreenshot(binding, 'light-settings_metering_screen_layout'); - - await tester.tapCancelButton(); - await tester.tapDescendantTextOf(S.current.equipmentProfiles); - await tester.pumpAndSettle(); - await tester.tapDescendantTextOf(mockEquipmentProfiles.first.name); - await tester.pumpAndSettle(); - await tester.takeScreenshot(binding, 'light-equipment_profiles'); - - await tester.tap(find.byIcon(Icons.iso).first); - await tester.pumpAndSettle(); - await tester.takeScreenshot(binding, 'light-equipment_profiles_iso_picker'); + await tester.toggleIncidentMetering(7.3); + await tester.takeScreenshot(binding, 'light-metering_incident'); } - ); + + await tester.openAnimatedPicker(); + await tester.takeScreenshot(binding, 'light-metering_iso_picker'); + + await tester.tapCancelButton(); + await tester.tap(find.byTooltip(S.current.tooltipOpenSettings)); + await tester.pumpAndSettle(); + await tester.takeScreenshot(binding, 'light-settings'); + + await tester.tapDescendantTextOf(S.current.meteringScreenLayout); + await tester.takeScreenshot(binding, 'light-settings_metering_screen_layout'); + + await tester.tapCancelButton(); + await tester.tapDescendantTextOf(S.current.equipmentProfiles); + await tester.pumpAndSettle(); + await tester.tapDescendantTextOf(mockEquipmentProfiles.first.name); + await tester.pumpAndSettle(); + await tester.takeScreenshot(binding, 'light-equipment_profiles'); + + await tester.tap(find.byIcon(Icons.iso).first); + await tester.pumpAndSettle(); + await tester.takeScreenshot(binding, 'light-equipment_profiles_iso_picker'); + }); /// and the additionally the first one with the dark theme testWidgets( 'Generate dark theme screenshots', (tester) async { mockSharedPrefs(ThemeType.dark, darkThemeColor); - await tester.pumpApplication(); + await tester.pumpApplication( + films: [_mockFilm], + selectedFilm: _mockFilm, + ); await tester.takePhoto(); await tester.takeScreenshot(binding, 'dark-metering_reflected'); @@ -127,10 +136,6 @@ final String _platformFolder = Platform.isAndroid ? 'android' : 'ios'; extension on WidgetTester { Future takeScreenshot(IntegrationTestWidgetsFlutterBinding binding, String name) async { - if (Platform.isAndroid) { - await binding.convertFlutterSurfaceToImage(); - await pumpAndSettle(); - } await binding.takeScreenshot("$_platformFolder/${const String.fromEnvironment('deviceName')}/$name"); await pumpAndSettle(); }