Skip to content

Commit

Permalink
feat(#687): introduce separate screencasts script
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Mar 7, 2024
1 parent db737d1 commit e132e3e
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 51 deletions.
36 changes: 19 additions & 17 deletions app/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,30 @@ This will generate icons for both iOS as well as Android.
## Updating screencast and screenshots

🙅 _Not working yet due to login redirect, but keeping script for Sinai_
_version (login without redirect)._
_version (login without redirect) – can adopt once different login types are_
_supported._

The `generate_screenshots/generate_screencast.sh` script will create screenshots
and screencasts. It uses Xcode to record the screencast and
[`ffmpeg`](https://ffmpeg.org/)
to cut the `full.mov` to relevant subsets.
Scripts were created to click through the app using tests and record the
screeen.

Run the script with `bash generate_screenshots/generate_screencast.sh`.
A simulator with the app in its initial state (or not installed) needs to be
running.

To only update the screenshots in `../docs/screenshots`
### Screencasts

The `generate_screendocs/generate_screencast.sh` script will create screencasts.
It uses Xcode to record the screencast and [`ffmpeg`](https://ffmpeg.org/)
to cut the `full.mov` to relevant subsets (needs to be installed).

Run the script with `bash generate_screendocs/generate_screencast.sh`.

## Screenshots

To update the screenshots in `../docs/screenshots`
(used in [📑 App screens](../docs/App-screens.md),
[📑 User instructions](../docs/User-instructions.html), and the
[README](./README.md)), run the following command after adding username and
password to:

```shell
flutter drive \
--driver=generate_screenshots/test_driver.dart \
--target=generate_screenshots/app_test.dart \
--dart-define=TEST_USER=<USERNAME> \
--dart-define=TEST_PASSWORD=<PASSWORD>
```
[README](./README.md)), run the following command:
`bash generate_screendocs/generate_screenshots.sh`.

If the error `The following MissingPluginException was thrown running a test:
MissingPluginException(No implementation found for method captureScreenshot on
Expand Down
27 changes: 27 additions & 0 deletions app/generate_screendocs/app_sequence_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:app/app.dart';
import 'package:app/common/module.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';

Future<void> loadApp(WidgetTester tester) async {
// Part before runApp in lib/main.dart
await initServices();
await updateGenotypeResults();
// Load the app
await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: PharMeApp(),
),
);
await tester.pumpAndSettle();
}

Future<void> cleanupApp() async {
// Part after runApp in lib/main.dart
await cleanupServices();
}

Future<void> wait(int seconds) async {
await Future.delayed(Duration(seconds: seconds));
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export RECORDING_PID=${!}
echo "Recording process up with pid: ${RECORDING_PID}"
echo "Running app"
flutter drive \
--driver=generate_screenshots/test_driver.dart \
--target=generate_screenshots/app_test.dart \
--dart-define=TEST_USER="$username" \
--dart-define=TEST_PASSWORD="$password" | tee "$test_log_path"
--driver=generate_screendocs/test_driver.dart \
--target=generate_screendocs/screencast_sequence.dart \
--dart-define=TEST_USER="$username" \
--dart-define=TEST_PASSWORD="$password" | tee "$test_log_path"

# Write cut timestamps from test.log to cut.log

Expand Down
10 changes: 10 additions & 0 deletions app/generate_screendocs/generate_screenshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

read -p "Enter username: " username
read -p "Enter password: " password

flutter drive \
--driver=generate_screendocs/test_driver.dart \
--target=generate_screendocs/screenshot_sequence.dart \
--dart-define=TEST_USER="$username" \
--dart-define=TEST_PASSWORD="$password"
41 changes: 41 additions & 0 deletions app/generate_screendocs/screencast_sequence.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Clicks though most parts of the app and outputs timestamp logs for cutting
// smaller screencasts in generate_screencast.sh script

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'app_sequence_utils.dart';

void logTimeStamp(String description) {
final timestamp = DateTime.now().millisecondsSinceEpoch;
// ignore: avoid_print
print('TIMESTAMP: $timestamp $description');
}

void main() {
group('click through the app and create screenshots', () {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('take screencast', (tester) async {
// ignore: unused_local_variable
const username = String.fromEnvironment('TEST_USER');
// ignore: unused_local_variable
const password = String.fromEnvironment('TEST_PASSWORD');

await loadApp(tester);
logTimeStamp('test_start');

// login
await wait(5);
logTimeStamp('login');

// login-redirect (not working; only taking screenshot of loading screen)
// could try to use cubit function to directly sign in which will only
// open the webview and close it again
// await tester.tap(find.byType(FullWidthButton).first);
// await Future.delayed(Duration(seconds: 3)); // wait for dialog
// await takeScreenshot(tester, binding, 'login-redirect');

await cleanupApp();
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import 'dart:io';

import 'package:app/app.dart';
import 'package:app/common/module.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:provider/provider.dart';

import 'app_sequence_utils.dart';

Future<void> takeScreenshot(
WidgetTester tester,
Expand All @@ -21,12 +20,6 @@ Future<void> takeScreenshot(
await binding.takeScreenshot(fileName);
}

void logTimeStamp(String description) {
final timestamp = DateTime.now().millisecondsSinceEpoch;
// ignore: avoid_print
print('TIMESTAMP: $timestamp $description');
}

void main() {
group('click through the app and create screenshots', () {
final binding = IntegrationTestWidgetsFlutterBinding();
Expand All @@ -37,38 +30,20 @@ void main() {
// ignore: unused_local_variable
const password = String.fromEnvironment('TEST_PASSWORD');

// Part before runApp in lib/main.dart
await initServices();
await updateGenotypeResults();

// Load the app
await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: PharMeApp(),
),
);
await tester.pumpAndSettle();

logTimeStamp('test_start');

// Click though the app and create screenshots
await loadApp(tester);

// login
await Future.delayed(Duration(seconds: 5)); // wait for logo & screencast
await wait(5); // wait for logo
await takeScreenshot(tester, binding, 'login');

logTimeStamp('login');

// login-redirect (not working; only taking screenshot of loading screen)
// could try to use cubit function to directly sign in which will only
// open the webview and close it again
// await tester.tap(find.byType(FullWidthButton).first);
// await Future.delayed(Duration(seconds: 3)); // wait for dialog
// await takeScreenshot(tester, binding, 'login-redirect');

// Part after runApp in lib/main.dart
await cleanupServices();
await cleanupApp();
});
});
}
File renamed without changes.

0 comments on commit e132e3e

Please sign in to comment.