diff --git a/packages/e2e/example/android/app/build.gradle b/packages/e2e/example/android/app/build.gradle index 527ed2dd38e0..f6d35e213d40 100644 --- a/packages/e2e/example/android/app/build.gradle +++ b/packages/e2e/example/android/app/build.gradle @@ -56,6 +56,8 @@ flutter { dependencies { testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' -} + testImplementation "com.google.truth:truth:1.0" + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + api 'androidx.test:core:1.2.0' +} \ No newline at end of file diff --git a/packages/e2e/example/android/app/src/androidTest/java/com/example/e2e_example/MainActivityEspressoTest.java b/packages/e2e/example/android/app/src/androidTest/java/com/example/e2e_example/MainActivityEspressoTest.java new file mode 100644 index 000000000000..4f05fcdf7104 --- /dev/null +++ b/packages/e2e/example/android/app/src/androidTest/java/com/example/e2e_example/MainActivityEspressoTest.java @@ -0,0 +1,36 @@ +package com.example.e2e_example; + +import static androidx.test.espresso.Espresso.pressBackUnconditionally; +import static androidx.test.espresso.flutter.EspressoFlutter.onFlutterWidget; +import static androidx.test.espresso.flutter.action.FlutterActions.click; +import static androidx.test.espresso.flutter.assertion.FlutterAssertions.matches; +import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withText; +import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withTooltip; +import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withValueKey; + +import androidx.test.core.app.ActivityScenario; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.rule.ActivityTestRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public final class MainActivityEspressoTest { + + @Rule + public ActivityTestRule myActivityTestRule = + new ActivityTestRule<>(MainActivity.class, true, false); + + @Before + public void setUp() { + ActivityScenario.launch(MainActivity.class); + } + + @Test + public void checkText() throws Exception { + onFlutterWidget(withValueKey("ResultText")) + .check(matches(withText("Platform: android"))); + } +} \ No newline at end of file diff --git a/packages/e2e/example/android/app/src/debug/AndroidManifest.xml b/packages/e2e/example/android/app/src/debug/AndroidManifest.xml index 5d4aea26b1dd..4ae66cfc2cdb 100644 --- a/packages/e2e/example/android/app/src/debug/AndroidManifest.xml +++ b/packages/e2e/example/android/app/src/debug/AndroidManifest.xml @@ -4,4 +4,5 @@ to allow setting breakpoints, to provide hot reload, etc. --> + diff --git a/packages/e2e/example/pubspec.yaml b/packages/e2e/example/pubspec.yaml index 9ef6098477e3..9ceb07b688ff 100644 --- a/packages/e2e/example/pubspec.yaml +++ b/packages/e2e/example/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: flutter: sdk: flutter - + espresso: ^0.0.1+3 cupertino_icons: ^0.1.2 dev_dependencies: diff --git a/packages/e2e/lib/e2e.dart b/packages/e2e/lib/e2e.dart index eef594a6f99e..ebd1ffcd5d30 100644 --- a/packages/e2e/lib/e2e.dart +++ b/packages/e2e/lib/e2e.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:async'; +import 'package:flutter_driver/driver_extension.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; @@ -10,6 +11,9 @@ import 'package:flutter/widgets.dart'; import '_extension_io.dart' if (dart.library.html) '_extension_web.dart'; +const String _extensionMethodName = 'driver'; +const String _extensionMethod = 'ext.flutter.$_extensionMethodName'; + /// A subclass of [LiveTestWidgetsFlutterBinding] that reports tests results /// on a channel to adapt them to native instrumentation test format. class E2EWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding { @@ -56,33 +60,18 @@ class E2EWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding { @override void initServiceExtensions() { super.initServiceExtensions(); - Future> callback(Map params) async { - final String command = params['command']; - Map response; - switch (command) { - case 'request_data': - final bool allTestsPassed = await _allTestsPassed.future; - response = { - 'message': allTestsPassed ? 'pass' : 'fail', - }; - break; - case 'get_health': - response = {'status': 'ok'}; - break; - default: - throw UnimplementedError('$command is not implemented'); - } - return { - 'isError': false, - 'response': response, - }; + Future handler(_) async { + final bool allTestsPassed = await _allTestsPassed.future; + return allTestsPassed ? 'pass' : 'fail'; } - + final FlutterDriverExtension extension = FlutterDriverExtension(handler, false); + registerServiceExtension( + name: _extensionMethodName, + callback: extension.call, + ); if (kIsWeb) { - registerWebServiceExtension(callback); + registerWebServiceExtension(extension.call); } - - registerServiceExtension(name: 'driver', callback: callback); } @override