Skip to content

Commit

Permalink
Add integration test for Android (using Espresso)
Browse files Browse the repository at this point in the history
  • Loading branch information
FirentisTFW committed Dec 19, 2024
1 parent 00f66e6 commit 6297663
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ flutter {
}

dependencies {
testImplementation 'androidx.test.ext:junit:1.2.1'
testImplementation "com.google.truth:truth:1.1.3"
testImplementation 'junit:junit:4.13'
testImplementation 'org.robolectric:robolectric:4.10.3'
testImplementation 'org.mockito:mockito-core:5.0.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation project(':espresso')
api 'androidx.test:core:1.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.videoplayerexample;

import static androidx.test.espresso.flutter.EspressoFlutter.onFlutterWidget;
import static androidx.test.espresso.flutter.EspressoFlutter.WidgetInteraction;
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.isExisting;
import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withText;
import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withValueKey;

import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class VideoPlayerUITest {

@Rule
public ActivityScenarioRule<DriverExtensionActivity> activityRule =
new ActivityScenarioRule<>(DriverExtensionActivity.class);

@Test
public void playVideo() {
WidgetInteraction remoteTab = onFlutterWidget(withText("Remote"));
remoteTab.check(matches(isExisting()));

for (String tabName : new String[] {"Platform view", "Texture view"}) {
WidgetInteraction viewTypeTab = onFlutterWidget(withText(tabName));
viewTypeTab.check(matches(isExisting()));
viewTypeTab.perform(click());

WidgetInteraction playButton = onFlutterWidget(withValueKey("Play"));
playButton.check(matches(isExisting()));
playButton.perform(click());

WidgetInteraction playbackSpeed1x = onFlutterWidget(withText("1.0x"));
playbackSpeed1x.check(matches(isExisting()));
playbackSpeed1x.perform(click());

WidgetInteraction playbackSpeed5xButton = onFlutterWidget(withText("5.0x"));
playbackSpeed5xButton.check(matches(isExisting()));
playbackSpeed5xButton.perform(click());

WidgetInteraction playbackSpeed5x = onFlutterWidget(withText("5.0x"));
playbackSpeed5x.check(matches(isExisting()));
}

for (String[] tabData :
new String[][] {{"Asset", "With assets mp4"}, {"Remote", "With remote mp4"}}) {
String tabName = tabData[0];
String videoDescription = tabData[1];
WidgetInteraction tab = onFlutterWidget(withText(tabName));
WidgetInteraction tabDescription = onFlutterWidget(withText(videoDescription));
tab.check(matches(isExisting()));

// TODO(FirentisTFW): Assert that testDescription is not visible before we tap on tab.
// This should be done once the Espresso API allows us to perform such an assertion. See
// https://github.com/flutter/flutter/issues/160599

tab.perform(click());

tab.check(matches(isExisting()));
tabDescription.check(matches(isExisting()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<application android:usesCleartextTraffic="true">
<activity
android:name="io.flutter.plugins.videoplayerexample.DriverExtensionActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.Entrypoint"
android:value="integrationTestMain" />
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.videoplayerexample;

import io.flutter.embedding.android.FlutterActivity;

/** Test Activity that sets the name of the Dart method entrypoint in the manifest. */
public class DriverExtensionActivity extends FlutterActivity {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">www.sample-videos.com</domain>
<domain includeSubdomains="true">184.72.239.149</domain>
<!-- Needed for Espresso integration test -->
<domain includeSubdomains="true">127.0.0.1</domain>
</domain-config>
</network-security-config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:video_player_example/main.dart' as app;

@pragma('vm:entry-point')
void integrationTestMain() {
enableFlutterDriverExtension();

app.main();
}

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

// Since this test is lacking integration tests, this test ensures the example
// app can be launched on an emulator/device.
testWidgets('Launch Test', (WidgetTester tester) async {});
}

0 comments on commit 6297663

Please sign in to comment.