diff --git a/README.md b/README.md index f31216b..4b29f37 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ Calculator - [Caster.IO](https://caster.io) project to showcase testing techniqu [Lesson 24: Running integration tests with flutter_driver](https://caster.io/lessons/lesson-24-running-integration-tests-with-flutter_driver) 👉🏾 [Branch](https://github.com/samuelematias/calculator_app/tree/lesson24) +[Lesson 25: Taking automated screenshots of your application](https://caster.io/lessons/lesson-25-taking-automated-screenshots-of-your-application) 👉🏾 [Branch](https://github.com/samuelematias/calculator_app/tree/lesson25) + ## License ``` diff --git a/pubspec.lock b/pubspec.lock index 036c626..21480bf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -210,6 +210,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.4" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" io: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c8093ca..b4a04c8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,6 +10,7 @@ dependencies: sdk: flutter calculator: path: packages/calculator + intl: ^0.16.1 material_segmented_control: 2.1.0+1 dev_dependencies: diff --git a/screenshots/entered_10-2020-12-02 19:31:51.221219.png b/screenshots/entered_10-2020-12-02 19:31:51.221219.png new file mode 100644 index 0000000..ee19cc7 Binary files /dev/null and b/screenshots/entered_10-2020-12-02 19:31:51.221219.png differ diff --git a/screenshots/entered_10-2020-12-02 19:32:29.018723.png b/screenshots/entered_10-2020-12-02 19:32:29.018723.png new file mode 100644 index 0000000..044331f Binary files /dev/null and b/screenshots/entered_10-2020-12-02 19:32:29.018723.png differ diff --git a/screenshots/entered_5-2020-12-02 19:31:48.280792.png b/screenshots/entered_5-2020-12-02 19:31:48.280792.png new file mode 100644 index 0000000..4aecc6b Binary files /dev/null and b/screenshots/entered_5-2020-12-02 19:31:48.280792.png differ diff --git a/screenshots/entered_5-2020-12-02 19:32:26.223478.png b/screenshots/entered_5-2020-12-02 19:32:26.223478.png new file mode 100644 index 0000000..2360be4 Binary files /dev/null and b/screenshots/entered_5-2020-12-02 19:32:26.223478.png differ diff --git a/screenshots/no_values_entered-2020-12-02 19:31:46.060957.png b/screenshots/no_values_entered-2020-12-02 19:31:46.060957.png new file mode 100644 index 0000000..bd52c35 Binary files /dev/null and b/screenshots/no_values_entered-2020-12-02 19:31:46.060957.png differ diff --git a/screenshots/no_values_entered-2020-12-02 19:32:23.839586.png b/screenshots/no_values_entered-2020-12-02 19:32:23.839586.png new file mode 100644 index 0000000..58a734b Binary files /dev/null and b/screenshots/no_values_entered-2020-12-02 19:32:23.839586.png differ diff --git a/screenshots/result_is_50-2020-12-02 19:31:53.282333.png b/screenshots/result_is_50-2020-12-02 19:31:53.282333.png new file mode 100644 index 0000000..ee19cc7 Binary files /dev/null and b/screenshots/result_is_50-2020-12-02 19:31:53.282333.png differ diff --git a/screenshots/result_is_50-2020-12-02 19:32:31.147872.png b/screenshots/result_is_50-2020-12-02 19:32:31.147872.png new file mode 100644 index 0000000..d555f34 Binary files /dev/null and b/screenshots/result_is_50-2020-12-02 19:32:31.147872.png differ diff --git a/test_driver/calculator_app_test.dart b/test_driver/calculator_app_test.dart index eafb18f..97fe8b0 100644 --- a/test_driver/calculator_app_test.dart +++ b/test_driver/calculator_app_test.dart @@ -1,4 +1,8 @@ +import 'dart:io'; +import 'dart:math'; + import 'package:flutter_driver/flutter_driver.dart'; +import 'package:intl/intl.dart'; import 'package:test/test.dart'; void main() { @@ -22,14 +26,35 @@ void main() { }); test('multiplying 5 and 10 shows 50', () async { + await driver.takeScreenshot('no_values_entered'); await driver.tap(find.byValueKey('textField_top_multiplied by')); await driver.enterText('5'); + await driver.takeScreenshot('entered_5'); await driver.scrollUntilVisible( find.byValueKey('textField_bottom_multiplied by'), find.text('multiplied by'), ); await driver.tap(find.byValueKey('textField_bottom_multiplied by')); await driver.enterText('10'); + await driver.takeScreenshot('entered_10'); await driver.waitFor(find.text('is 50.0')); + await driver.takeScreenshot('result_is_50'); }); } + +extension on FlutterDriver { + Future takeScreenshot(String name) async { + final DateTime now = DateTime.now(); + final DateFormat formatter = DateFormat('yyyy-MM-dd hh-mm-ss'); + final String formatted = formatter.format(now); + print(formatted); + final filePath = File('screenshots/$name-$now.png'); + if (await filePath.exists()) { + await filePath.delete(recursive: true); + } + final file = await filePath.create(recursive: true); + final png = await screenshot(); + file.writeAsBytesSync(png); + print('screenshot with name $name was taken'); + } +}