Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 25: Taking automated screenshots of your application #25

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
sdk: flutter
calculator:
path: packages/calculator
intl: ^0.16.1
material_segmented_control: 2.1.0+1

dev_dependencies:
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions test_driver/calculator_app_test.dart
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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<void> 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');
}
}