Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[e2e] Add customizable flutter_driver adaptor #2859

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/e2e/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.3

* Add customizable `flutter_driver` adaptor.

## 0.6.2+1

* Fix incorrect test results when one test passes then another fails
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ iOS support is not available yet, but is planned in the future.

Add a dependency on the `e2e` package in the
`dev_dependencies` section of pubspec.yaml. For plugins, do this in the
pubspec.yaml of the example app.
`pubspec.yaml` of the example app.

Invoke `E2EWidgetsFlutterBinding.ensureInitialized()` at the start
of a test file, e.g.
Expand Down Expand Up @@ -45,7 +45,7 @@ import 'dart:async';

import 'package:e2e/e2e_driver.dart' as e2e;

Future<void> main() async => e2e.main();
Future<void> main() async => e2e.e2eDriver();

```

Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/example/test_driver/example_e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import 'dart:async';

import 'package:e2e/e2e_driver.dart' as e2e;

Future<void> main() async => e2e.main();
Future<void> main() async => e2e.e2eDriver();
51 changes: 48 additions & 3 deletions packages/e2e/lib/e2e_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,60 @@ import 'dart:io';
import 'package:e2e/common.dart' as e2e;
import 'package:flutter_driver/flutter_driver.dart';

Future<void> main() async {
Future<void> main() => e2eDriver();

/// Adaptor to run E2E test using `flutter drive`.
///
/// `timeout` controls the longest time waited before the test ends.
/// It is not necessarily the execution time for the test app: the test may
/// finish sooner than the `timeout`.
///
/// `traceTimeline` flag controls if timeline and timeline summary should be
/// collected.
///
/// `testName` is used as the file name for the output timeline files.
///
/// To an E2E test `<test_name>.dart` using `flutter drive`, put a file named
/// `<test_name>_test.dart` in the app's `test_driver` directory:
///
/// ```dart
/// import 'dart:async';
///
/// import 'package:e2e/e2e_driver.dart' as e2e;
///
/// Future<void> main() async => e2e.e2eDriver();
///
/// ```
Future<void> e2eDriver({
Duration timeout = const Duration(minutes: 1),
bool traceTimeline = false,
String testName,
}) async {
assert(timeout != null);
assert(!traceTimeline || testName != null);
final FlutterDriver driver = await FlutterDriver.connect();
final String jsonResult =
await driver.requestData(null, timeout: const Duration(minutes: 1));
String jsonResult;
Timeline timeline;
Future<void> runner() async {
jsonResult = await driver.requestData(null, timeout: timeout);
}

if (traceTimeline) {
timeline = await driver.traceAction(runner);
// In the traceAction call runner is awaited.
} else {
await runner();
}
final e2e.Response response = e2e.Response.fromJson(jsonResult);
await driver.close();

if (response.allTestsPassed) {
print('All tests passed.');
if (traceTimeline) {
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(testName, pretty: true);
await summary.writeSummaryToFile(testName, pretty: true);
}
exit(0);
} else {
print('Failure Details:\n${response.formattedFailureDetails}');
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: e2e
description: Runs tests that use the flutter_test API as integration tests.
version: 0.6.2+1
version: 0.6.3
homepage: https://github.com/flutter/plugins/tree/master/packages/e2e

environment:
Expand Down