Skip to content

Commit

Permalink
Merge pull request #25 from samuelematias/lesson25
Browse files Browse the repository at this point in the history
Lesson 25: Taking automated screenshots of your application
  • Loading branch information
samuelematias committed Dec 2, 2020
2 parents fb215e1 + b0dffd0 commit a1119dd
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 0 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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');
}
}

0 comments on commit a1119dd

Please sign in to comment.