Skip to content

Commit cf9250e

Browse files
Nurhan TurgutEdwinRomelta
authored andcommitted
[web] adding a test for e2e web testing. (flutter#2554)
* adding a test for e2e web testing. * chaning the changelog. updating pubspec.yaml version. fixing analyze * merging the changelog * addressing reviewer comments * fix format. addressing reviewer comments * try to run chromedriver on the backend * chrome driver is was running as the main task, preventing test from running . use background_task to run it. use ENV for directory change * change in scripts. remove list from backfround task. change argument of driver * removed background task. it wasn't using the same path * run web tests only on browser * add test on to the web driver test as well. drive-examples are still failing * fix the imports * trying reviever suggestion for drive_example compile errors * test _ imports * Revert "test _ imports" This reverts commit 7cf24d6. * removing the web_test driver file upon reviewers suggestion * format fix
1 parent 4ba2a3e commit cf9250e

File tree

17 files changed

+223
-46
lines changed

17 files changed

+223
-46
lines changed

.cirrus.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ task:
66
dockerfile: .ci/Dockerfile
77
cpu: 8
88
memory: 16G
9+
env:
10+
E2E_PATH: "./packages/e2e"
911
upgrade_script:
1012
- flutter channel stable
1113
- flutter upgrade
@@ -45,6 +47,19 @@ task:
4547
- if [[ "$CHANNEL" -eq "stable" ]]; then find . | grep _web$ | xargs rm -rf; fi
4648
- flutter channel $CHANNEL
4749
- ./script/build_all_plugins_app.sh apk
50+
- name: e2e_web_smoke_test
51+
# Tests e2e example test in web.
52+
only_if: "changesInclude('.cirrus.yml', 'packages/e2e/**') || $CIRRUS_PR == ''"
53+
install_script:
54+
- flutter config --enable-web
55+
- git clone https://github.com/flutter/web_installers.git
56+
- cd web_installers/packages/web_drivers/
57+
- pub get
58+
- dart lib/web_driver_installer.dart chromedriver --install-only
59+
- ./chromedriver/chromedriver --port=4444 &
60+
test_script:
61+
- cd $E2E_PATH/example/
62+
- flutter drive -v --target=test_driver/example_e2e.dart -d web-server --release --browser-name=chrome
4863
- name: build-apks+java-test+firebase-test-lab
4964
env:
5065
matrix:

packages/e2e/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.4+4
2+
3+
* Fixed a hang that occurred on platforms that don't have a `MethodChannel` listener registered..
4+
15
## 0.2.4+3
26

37
* Fixed code snippet in the readme under the "Using Flutter driver to run tests" section.

packages/e2e/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ cd example
6969
flutter drive --driver=test_driver/<package_name>_test.dart test/<package_name>_e2e.dart
7070
```
7171

72+
You can run tests on web on release mode.
73+
74+
First you need to make sure you have downloaded the driver for the browser.
75+
76+
```
77+
cd example
78+
flutter drive -v --target=test_driver/<package_name>dart -d web-server --release --browser-name=chrome
79+
```
80+
7281
## Android device testing
7382

7483
Create an instrumentation test file in your application's

packages/e2e/example/lib/main.dart

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
1-
import 'dart:io' show Platform;
2-
import 'package:flutter/material.dart';
1+
import 'my_app.dart' if (dart.library.html) 'my_web_app.dart';
32

43
// ignore_for_file: public_member_api_docs
54

6-
void main() => runApp(MyApp());
7-
8-
class MyApp extends StatefulWidget {
9-
@override
10-
_MyAppState createState() => _MyAppState();
11-
}
12-
13-
class _MyAppState extends State<MyApp> {
14-
@override
15-
Widget build(BuildContext context) {
16-
return MaterialApp(
17-
home: Scaffold(
18-
appBar: AppBar(
19-
title: const Text('Plugin example app'),
20-
),
21-
body: Center(
22-
child: Text('Platform: ${Platform.operatingSystem}\n'),
23-
),
24-
),
25-
);
26-
}
27-
}
5+
void main() => startApp();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'dart:io' show Platform;
2+
import 'package:flutter/material.dart';
3+
4+
// ignore_for_file: public_member_api_docs
5+
6+
void startApp() => runApp(MyApp());
7+
8+
class MyApp extends StatefulWidget {
9+
@override
10+
_MyAppState createState() => _MyAppState();
11+
}
12+
13+
class _MyAppState extends State<MyApp> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return MaterialApp(
17+
home: Scaffold(
18+
appBar: AppBar(
19+
title: const Text('Plugin example app'),
20+
),
21+
body: Center(
22+
child: Text('Platform: ${Platform.operatingSystem}\n'),
23+
),
24+
),
25+
);
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'dart:html' as html;
2+
import 'package:flutter/material.dart';
3+
4+
// ignore_for_file: public_member_api_docs
5+
6+
void startApp() => runApp(MyWebApp());
7+
8+
class MyWebApp extends StatefulWidget {
9+
@override
10+
_MyWebAppState createState() => _MyWebAppState();
11+
}
12+
13+
class _MyWebAppState extends State<MyWebApp> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return MaterialApp(
17+
home: Scaffold(
18+
appBar: AppBar(
19+
title: const Text('Plugin example app'),
20+
),
21+
body: Center(
22+
key: Key('mainapp'),
23+
child: Text('Platform: ${html.window.navigator.platform}\n'),
24+
),
25+
),
26+
);
27+
}
28+
}

packages/e2e/example/test_driver/example_e2e.dart

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,12 @@
55
// gestures. You can also use WidgetTester to find child widgets in the widget
66
// tree, read text, and verify that the values of widget properties are correct.
77

8-
import 'dart:io' show Platform;
9-
import 'package:flutter/material.dart';
10-
import 'package:flutter_test/flutter_test.dart';
118
import 'package:e2e/e2e.dart';
129

13-
import 'package:e2e_example/main.dart';
10+
import 'example_e2e_io.dart' if (dart.library.html) 'example_e2e_web.dart'
11+
as tests;
1412

1513
void main() {
1614
E2EWidgetsFlutterBinding.ensureInitialized();
17-
testWidgets('verify text', (WidgetTester tester) async {
18-
// Build our app and trigger a frame.
19-
await tester.pumpWidget(MyApp());
20-
21-
// Verify that platform version is retrieved.
22-
expect(
23-
find.byWidgetPredicate(
24-
(Widget widget) =>
25-
widget is Text &&
26-
widget.data.startsWith('Platform: ${Platform.operatingSystem}'),
27-
),
28-
findsOneWidget,
29-
);
30-
});
15+
tests.main();
3116
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This is a basic Flutter widget test.
2+
//
3+
// To perform an interaction with a widget in your test, use the WidgetTester
4+
// utility that Flutter provides. For example, you can send tap and scroll
5+
// gestures. You can also use WidgetTester to find child widgets in the widget
6+
// tree, read text, and verify that the values of widget properties are correct.
7+
8+
import 'dart:io' show Platform;
9+
import 'package:flutter/material.dart';
10+
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:e2e/e2e.dart';
12+
13+
import 'package:e2e_example/main.dart' as app;
14+
15+
void main() {
16+
E2EWidgetsFlutterBinding.ensureInitialized();
17+
testWidgets('verify text', (WidgetTester tester) async {
18+
// Build our app and trigger a frame.
19+
app.main();
20+
21+
// Trigger a frame.
22+
await tester.pumpAndSettle();
23+
24+
// Verify that platform version is retrieved.
25+
expect(
26+
find.byWidgetPredicate(
27+
(Widget widget) =>
28+
widget is Text &&
29+
widget.data.startsWith('Platform: ${Platform.operatingSystem}'),
30+
),
31+
findsOneWidget,
32+
);
33+
});
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This is a basic Flutter widget test.
2+
//
3+
// To perform an interaction with a widget in your test, use the WidgetTester
4+
// utility that Flutter provides. For example, you can send tap and scroll
5+
// gestures. You can also use WidgetTester to find child widgets in the widget
6+
// tree, read text, and verify that the values of widget properties are correct.
7+
8+
import 'dart:html' as html;
9+
import 'package:flutter/material.dart';
10+
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:e2e/e2e.dart';
12+
13+
import 'package:e2e_example/main.dart' as app;
14+
15+
void main() {
16+
E2EWidgetsFlutterBinding.ensureInitialized();
17+
testWidgets('verify text', (WidgetTester tester) async {
18+
// Build our app and trigger a frame.
19+
app.main();
20+
21+
// Trigger a frame.
22+
await tester.pumpAndSettle();
23+
24+
// Verify that platform is retrieved.
25+
expect(
26+
find.byWidgetPredicate(
27+
(Widget widget) =>
28+
widget is Text &&
29+
widget.data
30+
.startsWith('Platform: ${html.window.navigator.platform}\n'),
31+
),
32+
findsOneWidget,
33+
);
34+
});
35+
}

packages/e2e/example/test_driver/failure.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
66
import 'package:flutter_test/flutter_test.dart';
77
import 'package:e2e/e2e.dart';
88

9-
import 'package:e2e_example/main.dart';
9+
import 'package:e2e_example/main.dart' as app;
1010

1111
// Tests the failure behavior of the E2EWidgetsFlutterBinding
1212
//
@@ -21,10 +21,10 @@ void main() {
2121

2222
testWidgets('failure 1', (WidgetTester tester) async {
2323
// Build our app and trigger a frame.
24-
await tester.pumpWidget(MyApp());
24+
app.main();
2525

2626
// Verify that platform version is retrieved.
27-
expect(
27+
await expectLater(
2828
find.byWidgetPredicate(
2929
(Widget widget) =>
3030
widget is Text && widget.data.startsWith('This should fail'),

0 commit comments

Comments
 (0)