summaryrefslogtreecommitdiff
path: root/espresso/espresso-lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/UiController.java
diff options
context:
space:
mode:
authorNick Korostelev <nkorsote@google.com>2014-04-09 18:16:48 -0700
committerNick Korostelev <nkorsote@google.com>2014-06-17 11:58:01 -0700
commitf69eb9ac2856f470cb79f57141f711ed3ceed99d (patch)
tree252d2ef648fed85c82dbdb99e7c1e077de1a3b4a /espresso/espresso-lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/UiController.java
parent1afabcc1a3db33f786ff7cc0c8d72e40990c8876 (diff)
downloadtesting-f69eb9ac2856f470cb79f57141f711ed3ceed99d.tar.gz
port Espresso to Android repo
- Completely restructured the project to match Gradle convention - Added several Android.mk to build using make. - Added build.gradle to build using Gradle. - Fixed package names to avoid conflicts - Requires several prebuilt Jars, added README to outline versions and licenses for legal. - Dependent libraries that don’t get JarJar’ed are linked to from the local prebuild maven repo. - Bumped up the version of dependent libraries that didn’t create compatibility issues - Cleaned up bin/ dir and renamed it to libs/ - Removed maven support, removed pom.xml files - Removed Android make support, removed Android.mk files - Removed testrunner and testrunner-runtime, using binaries instead. There is a separate initiative to add them to Android repo. - Separated IdlingResource to it's own library to expose and decouple this interface which is frequently referenced by code in the app-under-test - added copyright Workaround for Android Gradle plugin limitation - Created two separate modules espresso-lib-tests and espresso-contrib-tests that will include the unit tests for the corresponding libs. Current limitations: - Gradle - no current support for setting a custom ‘targetPackage’ for espressi-lib and espresso-conrib unit tests ("gradle assembleDebugTest" will not work for espressi-lib and espresso-conrib). - Intellij Gradle plugin doesn't like multiple project sharing the same "main" source and variants Note: follow these steps if encounter ClassNotFoundException when running on physical device: 1. adb shell su 2. adb shell setprop dalvik.vm.dexopt-flags v=n,o=v 3. adb shell stop installd 4. adb shell start installd 5. reinstall apks Change-Id: I356150fcecb13537d212c180adea8f2cee916b81
Diffstat (limited to 'espresso/espresso-lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/UiController.java')
-rw-r--r--espresso/espresso-lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/UiController.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/espresso/espresso-lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/UiController.java b/espresso/espresso-lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/UiController.java
new file mode 100644
index 0000000..cf53d08
--- /dev/null
+++ b/espresso/espresso-lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/UiController.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.android.apps.common.testing.ui.espresso;
+
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+/**
+ * Provides base-level UI operations (such as injection of {@link MotionEvent}s) that can be used to
+ * build user actions such as clicks, scrolls, swipes, etc. This replaces parts of the android
+ * Instrumentation class that provides similar functionality. However, it provides a more advanced
+ * synchronization mechanism for test actions. The key differentiators are:
+ * <ul>
+ * <li>test actions are assumed to be called on the main thread
+ * <li>after a test action is initiated, execution blocks until all messages in the main message
+ * queue have been cleared.
+ * </ul>
+ */
+public interface UiController {
+ /**
+ * Injects a motion event into the application.
+ *
+ * @param event the (non-null!) event to inject
+ * @return true if the event was injected, false otherwise
+ * @throws InjectEventSecurityException if the event couldn't be injected because it would
+ * interact with another application.
+ */
+ boolean injectMotionEvent(MotionEvent event) throws InjectEventSecurityException;
+
+ /**
+ * Injects a key event into the application.
+ *
+ * @param event the (non-null!) event to inject
+ * @return true if the event was injected, false otherwise
+ * @throws InjectEventSecurityException if the event couldn't be injected because it would
+ * interact with another application.
+ */
+ boolean injectKeyEvent(KeyEvent event) throws InjectEventSecurityException;
+
+ /**
+ * Types a string into the application using series of {@link KeyEvent}s. It is up to the
+ * implementor to decide how to map the string to {@link KeyEvent} objects. if you need specific
+ * control over the key events generated use {@link #injectKeyEvent(KeyEvent)}.
+ *
+ * @param str the (non-null!) string to type
+ * @return true if the string was injected, false otherwise
+ * @throws InjectEventSecurityException if the events couldn't be injected because it would
+ * interact with another application.
+ */
+ boolean injectString(String str) throws InjectEventSecurityException;
+
+ /**
+ * Loops the main thread until the application goes idle.
+ *
+ * An empty task is immediately inserted into the task queue to ensure that if we're idle at this
+ * moment we'll return instantly.
+ */
+ void loopMainThreadUntilIdle();
+
+ /**
+ * Loops the main thread for a specified period of time.
+ *
+ * Control may not return immediately, instead it'll return after the time has passed and the
+ * queue is in an idle state again.
+ *
+ * @param millisDelay time to spend in looping the main thread
+ */
+ void loopMainThreadForAtLeast(long millisDelay);
+}