Skip to content

Commit 7f8ad8a

Browse files
authored
Add and use an integration test with native(ADB) screenshots (flutter#152326)
Closes flutter#152325. This PR is large due to generate `flutter create --platforms android`. A quick summary: - Moves the integration test from `packages/flutter_driver/test` to `dev/integration_tests` - Created a sample Flutter app that draws a blue rectangle - Forked a subset of `package:flutter_goldens` that will work on the standalone Dart VM - Forked a subset of `goldens.dart` (from `flutter_test`) to `src/native/goldens.dart` (i.e. `matchesGoldenFile`) This ... works locally, but as usual I have no idea if it will work on Skia Gold so let's roll some dice.
1 parent 4b5d24e commit 7f8ad8a

File tree

31 files changed

+932
-20
lines changed

31 files changed

+932
-20
lines changed

dev/bots/suite_runners/run_flutter_driver_android_tests.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
// found in the LICENSE file.
44

55
import 'package:path/path.dart' as path;
6+
import '../run_command.dart';
67
import '../utils.dart';
78

89
Future<void> runFlutterDriverAndroidTests() async {
910
print('Running Flutter Driver Android tests...');
1011

11-
await runDartTest(
12-
path.join(flutterRoot, 'packages', 'flutter_driver'),
13-
testPaths: <String>[
14-
'test/src/native_tests/android',
12+
// TODO(matanlurey): Should we be using another instrumentation method?
13+
await runCommand(
14+
'flutter',
15+
<String>[
16+
'drive',
1517
],
18+
workingDirectory: path.join(
19+
'dev',
20+
'integration_tests',
21+
'android_driver_test',
22+
),
1623
);
1724
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "6a346df51b97840ff2c06805e5482be28c6dd7c4"
8+
channel: "[user-branch]"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4
17+
base_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4
18+
- platform: android
19+
create_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4
20+
base_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4
21+
22+
# User provided section
23+
24+
# List of Local paths (relative to this file) that should be
25+
# ignored by the migrate tool.
26+
#
27+
# Files that are not part of the templates will be ignored by default.
28+
unmanaged_files:
29+
- 'lib/main.dart'
30+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Flutter Driver Android Integration Tests
2+
3+
This directory contains a sample app and tests that demonstrate how to use the
4+
(experimental) _native_ Flutter Driver API to drive Flutter apps that run on
5+
Android devices or emulators, interact with and capture screenshots of the app,
6+
and compare the screenshots against golden images.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/to/reference-keystore
11+
key.properties
12+
**/*.keystore
13+
**/*.jks
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
plugins {
6+
id "com.android.application"
7+
id "kotlin-android"
8+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
9+
id "dev.flutter.flutter-gradle-plugin"
10+
}
11+
12+
android {
13+
namespace = "com.example.android_driver_test"
14+
compileSdk = flutter.compileSdkVersion
15+
ndkVersion = flutter.ndkVersion
16+
17+
compileOptions {
18+
sourceCompatibility = JavaVersion.VERSION_1_8
19+
targetCompatibility = JavaVersion.VERSION_1_8
20+
}
21+
22+
kotlinOptions {
23+
jvmTarget = JavaVersion.VERSION_1_8
24+
}
25+
26+
defaultConfig {
27+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
28+
applicationId = "com.example.android_driver_test"
29+
// You can update the following values to match your application needs.
30+
// For more information, see: https://flutter.dev/to/review-gradle-config.
31+
minSdk = flutter.minSdkVersion
32+
targetSdk = flutter.targetSdkVersion
33+
versionCode = flutter.versionCode
34+
versionName = flutter.versionName
35+
}
36+
37+
buildTypes {
38+
release {
39+
// TODO: Add your own signing config for the release build.
40+
// Signing with the debug keys for now, so `flutter run --release` works.
41+
signingConfig = signingConfigs.debug
42+
}
43+
}
44+
}
45+
46+
flutter {
47+
source = "../.."
48+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
6+
<!-- The INTERNET permission is required for development. Specifically,
7+
the Flutter tool needs it to communicate with the running application
8+
to allow setting breakpoints, to provide hot reload, etc.
9+
-->
10+
<uses-permission android:name="android.permission.INTERNET"/>
11+
</manifest>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
6+
<application
7+
android:label="android_driver_test"
8+
android:name="${applicationName}"
9+
android:icon="@mipmap/ic_launcher">
10+
<activity
11+
android:name=".MainActivity"
12+
android:exported="true"
13+
android:launchMode="singleTop"
14+
android:taskAffinity=""
15+
android:theme="@style/LaunchTheme"
16+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
17+
android:hardwareAccelerated="true"
18+
android:windowSoftInputMode="adjustResize">
19+
<!-- Specifies an Android theme to apply to this Activity as soon as
20+
the Android process has started. This theme is visible to the user
21+
while the Flutter UI initializes. After that, this theme continues
22+
to determine the Window background behind the Flutter UI. -->
23+
<meta-data
24+
android:name="io.flutter.embedding.android.NormalTheme"
25+
android:resource="@style/NormalTheme"
26+
/>
27+
<intent-filter>
28+
<action android:name="android.intent.action.MAIN"/>
29+
<category android:name="android.intent.category.LAUNCHER"/>
30+
</intent-filter>
31+
</activity>
32+
<!-- Don't delete the meta-data below.
33+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
34+
<meta-data
35+
android:name="flutterEmbedding"
36+
android:value="2" />
37+
</application>
38+
<!-- Required to query activities that can process text, see:
39+
https://developer.android.com/training/package-visibility and
40+
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
41+
42+
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
43+
<queries>
44+
<intent>
45+
<action android:name="android.intent.action.PROCESS_TEXT"/>
46+
<data android:mimeType="text/plain"/>
47+
</intent>
48+
</queries>
49+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
@file:Suppress("PackageName")
6+
7+
package com.example.android_driver_test
8+
9+
import android.os.Bundle
10+
import androidx.core.view.WindowCompat
11+
import androidx.core.view.WindowInsetsCompat
12+
import androidx.core.view.WindowInsetsControllerCompat
13+
import io.flutter.embedding.android.FlutterActivity
14+
15+
class MainActivity : FlutterActivity() {
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
19+
// https://developer.android.com/training/system-ui
20+
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
21+
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
22+
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
23+
actionBar?.hide()
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<?xml version="1.0" encoding="utf-8"?>
6+
<!-- Modify this file to customize your launch splash screen -->
7+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
8+
<item android:drawable="?android:colorBackground" />
9+
10+
<!-- You can insert your own image assets here -->
11+
<!-- <item>
12+
<bitmap
13+
android:gravity="center"
14+
android:src="@mipmap/launch_image" />
15+
</item> -->
16+
</layer-list>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<?xml version="1.0" encoding="utf-8"?>
6+
<!-- Modify this file to customize your launch splash screen -->
7+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
8+
<item android:drawable="@android:color/white" />
9+
10+
<!-- You can insert your own image assets here -->
11+
<!-- <item>
12+
<bitmap
13+
android:gravity="center"
14+
android:src="@mipmap/launch_image" />
15+
</item> -->
16+
</layer-list>
Loading
Loading
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<?xml version="1.0" encoding="utf-8"?>
6+
<resources>
7+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
8+
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
9+
<!-- Show a splash screen on the activity. Automatically removed when
10+
the Flutter engine draws its first frame -->
11+
<item name="android:windowBackground">@drawable/launch_background</item>
12+
</style>
13+
<!-- Theme applied to the Android Window as soon as the process has started.
14+
This theme determines the color of the Android Window while your
15+
Flutter UI initializes, as well as behind your Flutter UI while its
16+
running.
17+
18+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
19+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
20+
<item name="android:windowBackground">?android:colorBackground</item>
21+
</style>
22+
</resources>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<?xml version="1.0" encoding="utf-8"?>
6+
<resources>
7+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
8+
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
9+
<!-- Show a splash screen on the activity. Automatically removed when
10+
the Flutter engine draws its first frame -->
11+
<item name="android:windowBackground">@drawable/launch_background</item>
12+
</style>
13+
<!-- Theme applied to the Android Window as soon as the process has started.
14+
This theme determines the color of the Android Window while your
15+
Flutter UI initializes, as well as behind your Flutter UI while its
16+
running.
17+
18+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
19+
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
20+
<item name="android:windowBackground">?android:colorBackground</item>
21+
</style>
22+
</resources>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2+
Use of this source code is governed by a BSD-style license that can be
3+
found in the LICENSE file. -->
4+
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
6+
<!-- The INTERNET permission is required for development. Specifically,
7+
the Flutter tool needs it to communicate with the running application
8+
to allow setting breakpoints, to provide hot reload, etc.
9+
-->
10+
<uses-permission android:name="android.permission.INTERNET"/>
11+
</manifest>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
allprojects {
6+
repositories {
7+
google()
8+
mavenCentral()
9+
}
10+
}
11+
12+
rootProject.buildDir = "../build"
13+
subprojects {
14+
project.buildDir = "${rootProject.buildDir}/${project.name}"
15+
}
16+
subprojects {
17+
project.evaluationDependsOn(":app")
18+
}
19+
20+
tasks.register("clean", Delete) {
21+
delete rootProject.buildDir
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
2+
android.useAndroidX=true
3+
android.enableJetifier=true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
zipStoreBase=GRADLE_USER_HOME
4+
zipStorePath=wrapper/dists
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
pluginManagement {
6+
def flutterSdkPath = {
7+
def properties = new Properties()
8+
file("local.properties").withInputStream { properties.load(it) }
9+
def flutterSdkPath = properties.getProperty("flutter.sdk")
10+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11+
return flutterSdkPath
12+
}()
13+
14+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
15+
16+
repositories {
17+
google()
18+
mavenCentral()
19+
gradlePluginPortal()
20+
}
21+
}
22+
23+
plugins {
24+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
25+
id "com.android.application" version "8.1.0" apply false
26+
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
27+
}
28+
29+
include ":app"

0 commit comments

Comments
 (0)