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

[espresso] Adds EspressoFlutter as a first-party plugin #2369

Merged
merged 43 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1743eab
Initial copy of e2e plugin renamed to espresso
collinjackson Nov 26, 2019
0bf791e
Switch to a new project based on template plugin
collinjackson Nov 26, 2019
f47c5a4
Update example app to be a button app
collinjackson Nov 26, 2019
45bf214
switch to Java
collinjackson Nov 26, 2019
195bb22
Add example Espresso test
collinjackson Nov 26, 2019
fded8ad
Midpoint check-in while addressing dependency errors
collinjackson Nov 26, 2019
60da0af
Demonstration of Espresso tests passing
collinjackson Nov 26, 2019
4f65053
All tests pass
collinjackson Nov 26, 2019
7c77635
Add shared preferences integration test
collinjackson Nov 26, 2019
86f133c
Fix test to match internal version
collinjackson Nov 26, 2019
02adfc8
Tests pass for shared prefs plugin
collinjackson Nov 26, 2019
f343591
Open source Espresso files
collinjackson Nov 26, 2019
521eb6c
License
collinjackson Dec 6, 2019
f2e0e56
SDK constraints
collinjackson Dec 6, 2019
6b86f04
Update README, changelog, remove test
collinjackson Dec 6, 2019
0b70161
Revert shared_preferences
collinjackson Dec 6, 2019
ce9de53
Update README.md
collinjackson Dec 7, 2019
cc2ebe5
Update README to make it clear this package is Android-only
collinjackson Dec 9, 2019
11b38af
Update licenses
collinjackson Dec 9, 2019
da89fee
Merge remote-tracking branch 'cj/new_espresso_plugin' into new_espres…
collinjackson Dec 9, 2019
211e358
remove commented dependencies
collinjackson Dec 9, 2019
b823741
More README updates
collinjackson Dec 9, 2019
5a1d274
Add a click test
collinjackson Dec 9, 2019
226a0d6
Fix build error
collinjackson Dec 9, 2019
2d0d9a1
More README updates
collinjackson Dec 9, 2019
0a2b5ab
fix file that wasn't meant to be checked in
collinjackson Dec 9, 2019
56360ff
Update README
collinjackson Dec 9, 2019
e3d340c
Merge remote-tracking branch 'origin/master' into new_espresso_plugin
collinjackson Dec 10, 2019
5377d27
Fix build failure
collinjackson Dec 10, 2019
8663ebd
Update README.md
collinjackson Dec 10, 2019
f69d012
Update README to clarify that iOS example is for the bots.
collinjackson Jan 9, 2020
a33410d
Code review feedback on plaintext traffic
collinjackson Jan 9, 2020
3a00269
Update README.md
collinjackson Jan 9, 2020
e5c1ae1
reformat
collinjackson Jan 9, 2020
5bf41b2
update pubspec.yaml
collinjackson Jan 9, 2020
9a85ad9
remove unused test
collinjackson Jan 9, 2020
d69e407
reformat
collinjackson Jan 9, 2020
6b6ff85
Merge remote-tracking branch 'origin/master' into new_espresso_plugin
collinjackson Jan 9, 2020
acef95e
Merge remote-tracking branch 'cj/new_espresso_plugin' into new_espres…
collinjackson Jan 9, 2020
a5a9c46
Fix analyzer issues
collinjackson Jan 9, 2020
8b6542b
fix ios build
collinjackson Jan 9, 2020
d18b2a0
remove lib/espresso.dart
collinjackson Jan 9, 2020
8129481
reformat
collinjackson Jan 9, 2020
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
7 changes: 7 additions & 0 deletions packages/espresso/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
10 changes: 10 additions & 0 deletions packages/espresso/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 0190e40457d43e17bdfaf046dfa634cbc5bf28b9
channel: unknown

project_type: plugin
3 changes: 3 additions & 0 deletions packages/espresso/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* Initial open-source release of Espresso bindings for Flutter.
27 changes: 27 additions & 0 deletions packages/espresso/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
121 changes: 121 additions & 0 deletions packages/espresso/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# espresso

Provides bindings for Espresso tests of Flutter Android apps.

## Installation

Add ```android:usesCleartextTraffic="true"``` in the ```<application>``` in the AndroidManifest.xml
of the Android app used for testing.
collinjackson marked this conversation as resolved.
Show resolved Hide resolved

Add dependencies to your build.gradle:

```
collinjackson marked this conversation as resolved.
Show resolved Hide resolved
dependencies {
testImplementation 'junit:junit:4.12'
testImplementation "com.google.truth:truth:1.0"
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

// Core library
api 'androidx.test:core:1.2.0'

// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'

// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test.ext:truth:1.0.0'
androidTestImplementation 'com.google.truth:truth:0.42'

// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'

// The following Espresso dependency can be either "implementation"
// or "androidTestImplementation", depending on whether you want the
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
}
```

Create an `android/app/src/androidTest` folder and put a test file in a package-appropriate subfolder, e.g. `android/app/src/androidTest/java/com/example/MainActivityTest.java`:

```
package com.example.espresso_example;

import static androidx.test.espresso.flutter.EspressoFlutter.onFlutterWidget;
import static androidx.test.espresso.flutter.action.FlutterActions.click;
import static androidx.test.espresso.flutter.action.FlutterActions.syntheticClick;
import static androidx.test.espresso.flutter.assertion.FlutterAssertions.matches;
import static androidx.test.espresso.flutter.matcher.FlutterMatchers.isDescendantOf;
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.withType;
import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withValueKey;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.flutter.EspressoFlutter.WidgetInteraction;
import androidx.test.espresso.flutter.assertion.FlutterAssertions;
import androidx.test.espresso.flutter.matcher.FlutterMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/** Unit tests for {@link EspressoFlutter}. */
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {

@Before
public void setUp() throws Exception {
ActivityScenario.launch(MainActivity.class);
}

@Test
public void performClick() {
onFlutterWidget(withTooltip("Increment")).perform(click());
onFlutterWidget(withValueKey("CountText")).check(matches(withText("Button tapped 1 time.")));
}
```

You'll need to create a test app that enables the Flutter driver extension.
You can put this in your test_driver/ folder, e.g. test_driver/example.dart.

```
import 'package:flutter_driver/driver_extension.dart';
import '../lib/main.dart' as app;

void main() {
enableFlutterDriverExtension();
app.main();
}
```

The following command line command runs the test locally:

```
./gradlew app:connectedAndroidTest -Ptarget=`pwd`/../test_driver/example.dart
```

Espresso tests can also be run on [Firebase Test Lab](https://firebase.google.com/docs/test-lab):

```
./gradlew app:assembleAndroidTest
./gradlew app:assembleDebug -Ptarget=<path_to_test>.dart
gcloud auth activate-service-account --key-file=<PATH_TO_KEY_FILE>
gcloud --quiet config set project <PROJECT_NAME>
gcloud firebase test android run --type instrumentation \
--app build/app/outputs/apk/debug/app-debug.apk \
--test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk\
--timeout 2m \
--results-bucket=<RESULTS_BUCKET> \
--results-dir=<RESULTS_DIRECTORY>
```
8 changes: 8 additions & 0 deletions packages/espresso/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
74 changes: 74 additions & 0 deletions packages/espresso/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
group 'com.example.espresso'
version '1.0'

buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
implementation 'com.google.guava:guava:28.1-android'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.google.code.gson:gson:2.8.6'
androidTestImplementation 'org.hamcrest:hamcrest:2.2'

testImplementation 'junit:junit:4.12'
testImplementation "com.google.truth:truth:1.0"
api 'androidx.test:runner:1.1.1'
api 'androidx.test.espresso:espresso-core:3.1.1'

// Core library
api 'androidx.test:core:1.0.0'

// AndroidJUnitRunner and JUnit Rules
api 'androidx.test:runner:1.1.0'
api 'androidx.test:rules:1.1.0'

// Assertions
api 'androidx.test.ext:junit:1.0.0'
api 'androidx.test.ext:truth:1.0.0'
api 'com.google.truth:truth:0.42'

// Espresso dependencies
api 'androidx.test.espresso:espresso-core:3.1.0'
api 'androidx.test.espresso:espresso-contrib:3.1.0'
api 'androidx.test.espresso:espresso-intents:3.1.0'
api 'androidx.test.espresso:espresso-accessibility:3.1.0'
api 'androidx.test.espresso:espresso-web:3.1.0'
api 'androidx.test.espresso.idling:idling-concurrent:3.1.0'

// The following Espresso dependency can be either "implementation"
// or "androidTestImplementation", depending on whether you want the
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
api 'androidx.test.espresso:espresso-idling-resource:3.1.0'
}


4 changes: 4 additions & 0 deletions packages/espresso/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Nov 26 13:04:21 PST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
1 change: 1 addition & 0 deletions packages/espresso/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'espresso'
3 changes: 3 additions & 0 deletions packages/espresso/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.espresso">
</manifest>
Loading