aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkjin <kjin@google.com>2017-01-18 09:37:51 -0800
committerKevin Jin <kjin@google.com>2017-02-17 14:42:32 -0800
commita0cf3e76f735ac94203335933692c9b0e6e8efaa (patch)
tree8c6f32089daea2b4909ad8a97c12e11bcd6ea1d2
parent91b56eb1cc3f3d971cd40b0f9e64d915eb00a88e (diff)
downloaddroiddriver-a0cf3e76f735ac94203335933692c9b0e6e8efaa.tar.gz
Deprecate custom io.appium.droiddriver.runner.TestRunner
Use standard android.support.test.runner.AndroidJUnitRunner ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=144844143
-rw-r--r--build.gradle8
-rw-r--r--droiddriver-android_support_test/AndroidManifest.xml5
-rw-r--r--droiddriver-android_support_test/build.gradle68
-rw-r--r--droiddriver-android_support_test/readme.md5
-rw-r--r--droiddriver-android_support_test/src/io/appium/droiddriver/android_support_test/D2AndroidJUnitRunner.java82
-rw-r--r--manualtest/AndroidManifest.xml2
-rw-r--r--manualtest/build.gradle2
-rw-r--r--src/io/appium/droiddriver/runner/MinSdkVersion.java3
-rw-r--r--src/io/appium/droiddriver/runner/TestRunner.java3
-rw-r--r--src/io/appium/droiddriver/runner/UseUiAutomation.java3
-rw-r--r--src/io/appium/droiddriver/util/ActivityUtils.java76
-rw-r--r--src/io/appium/droiddriver/util/InstrumentationUtils.java27
12 files changed, 79 insertions, 205 deletions
diff --git a/build.gradle b/build.gradle
index cbf12f1..8cc329e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -28,6 +28,14 @@ version = ddVersion
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'
+repositories {
+ jcenter()
+}
+
+dependencies {
+ compile 'com.android.support.test:runner:0.4.1'
+}
+
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked'
}
diff --git a/droiddriver-android_support_test/AndroidManifest.xml b/droiddriver-android_support_test/AndroidManifest.xml
deleted file mode 100644
index f9f47f8..0000000
--- a/droiddriver-android_support_test/AndroidManifest.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest
- package="io.appium.droiddriver.android_support_test">
-
-</manifest>
diff --git a/droiddriver-android_support_test/build.gradle b/droiddriver-android_support_test/build.gradle
deleted file mode 100644
index 9d71de2..0000000
--- a/droiddriver-android_support_test/build.gradle
+++ /dev/null
@@ -1,68 +0,0 @@
-buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.3.0'
- classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
- }
-}
-
-apply plugin: 'android-sdk-manager'
-apply plugin: 'com.android.library'
-
-ext.ddSnapshot = hasProperty('ddSnapshot')
-
-repositories {
- jcenter()
- if (ddSnapshot) {
- // For development only - droiddriver SNAPSHOTs published here
- maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
- }
-}
-
-dependencies {
- if (ddSnapshot) {
- // For development only.
- compile 'io.appium:droiddriver:1.0.0-SNAPSHOT'
- } else {
- compile 'io.appium:droiddriver:1.0.0-BETA1'
- }
-
- compile 'com.android.support.test:runner:0.4.1'
-}
-
-tasks.withType(JavaCompile) {
- options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked'
-}
-
-android {
- compileSdkVersion 23
- buildToolsVersion '21.1.2'
-
- defaultConfig {
- minSdkVersion 8
- targetSdkVersion 23
- versionCode 1
- }
-
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_7
- targetCompatibility JavaVersion.VERSION_1_7
- }
-
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- }
- }
-
- lintOptions {
- // Aborting on lint errors prevents jenkins from processing the Lint output
- // https://wiki.jenkins-ci.org/display/JENKINS/Android%20Lint%20Plugin
- abortOnError false
- }
-}
-
-//TODO: add script for publishing
diff --git a/droiddriver-android_support_test/readme.md b/droiddriver-android_support_test/readme.md
deleted file mode 100644
index f4d7ebb..0000000
--- a/droiddriver-android_support_test/readme.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# droiddriver-android_support_test
-
-An optional library that integrates DroidDriver with [the Android Support Test Library](https://code.google.com/p/android-test-kit/wiki/AndroidJUnitRunnerUserGuide).
-This is an experimental library because the Android Support Test Library is at early stage and many
-APIs are in internal packages. \ No newline at end of file
diff --git a/droiddriver-android_support_test/src/io/appium/droiddriver/android_support_test/D2AndroidJUnitRunner.java b/droiddriver-android_support_test/src/io/appium/droiddriver/android_support_test/D2AndroidJUnitRunner.java
deleted file mode 100644
index 89e32d1..0000000
--- a/droiddriver-android_support_test/src/io/appium/droiddriver/android_support_test/D2AndroidJUnitRunner.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (C) 2015 DroidDriver committers
- *
- * 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 io.appium.droiddriver.android_support_test;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.os.Looper;
-import android.support.test.runner.AndroidJUnitRunner;
-import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
-import android.support.test.runner.lifecycle.Stage;
-import android.util.Log;
-
-import java.util.Iterator;
-import java.util.concurrent.Callable;
-
-import io.appium.droiddriver.util.ActivityUtils;
-import io.appium.droiddriver.util.InstrumentationUtils;
-import io.appium.droiddriver.util.Logs;
-
-/**
- * Integrates DroidDriver with AndroidJUnitRunner. <p> TODO: support DroidDriver test filter
- * annotations.
- */
-public class D2AndroidJUnitRunner extends AndroidJUnitRunner {
- private static final Callable<Activity> GET_RUNNING_ACTIVITY = new Callable<Activity>() {
- @Override
- public Activity call() {
- Iterator<Activity> activityIterator = ActivityLifecycleMonitorRegistry.getInstance()
- .getActivitiesInStage(Stage.RESUMED).iterator();
- return activityIterator.hasNext() ? activityIterator.next() : null;
- }
- };
-
- /**
- * {@inheritDoc} <p> Initializes {@link InstrumentationUtils}.
- */
- @Override
- public void onCreate(Bundle arguments) {
- InstrumentationUtils.init(this, arguments);
- super.onCreate(arguments);
- }
-
- /**
- * {@inheritDoc} <p> Hooks {@link ActivityUtils#setRunningActivitySupplier} to {@link
- * ActivityLifecycleMonitorRegistry}.
- */
- @Override
- public void onStart() {
- ActivityUtils.setRunningActivitySupplier(new ActivityUtils.Supplier<Activity>() {
- @Override
- public Activity get() {
- try {
- // If this is called on main (UI) thread, don't call runOnMainSync
- if (Looper.myLooper() == Looper.getMainLooper()) {
- return GET_RUNNING_ACTIVITY.call();
- }
-
- return InstrumentationUtils.runOnMainSyncWithTimeout(GET_RUNNING_ACTIVITY);
- } catch (Exception e) {
- Logs.log(Log.WARN, e);
- return null;
- }
- }
- });
-
- super.onStart();
- }
-}
diff --git a/manualtest/AndroidManifest.xml b/manualtest/AndroidManifest.xml
index 7e07f25..da5117a 100644
--- a/manualtest/AndroidManifest.xml
+++ b/manualtest/AndroidManifest.xml
@@ -4,7 +4,7 @@
package="io.appium.droiddriver.manualtest">
<instrumentation
- android:name="io.appium.droiddriver.runner.TestRunner"
+ android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="io.appium.droiddriver.manualtest" />
<!-- Needed for Android.mk -->
diff --git a/manualtest/build.gradle b/manualtest/build.gradle
index 5be41b8..22731e4 100644
--- a/manualtest/build.gradle
+++ b/manualtest/build.gradle
@@ -16,7 +16,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
- testInstrumentationRunner 'io.appium.droiddriver.runner.TestRunner'
+ testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
sourceSets {
main {
diff --git a/src/io/appium/droiddriver/runner/MinSdkVersion.java b/src/io/appium/droiddriver/runner/MinSdkVersion.java
index a05b3fc..e7894cb 100644
--- a/src/io/appium/droiddriver/runner/MinSdkVersion.java
+++ b/src/io/appium/droiddriver/runner/MinSdkVersion.java
@@ -31,10 +31,13 @@ import java.lang.annotation.Target;
* As any annotations, it is useful only if it is processed by tools.
* {@link TestRunner} filters out tests with this annotation if the current
* device has a lower SDK version.
+ *
+ * @deprecated Use android.support.test.filters.SdkSuppress instead.
*/
@Inherited
@Target({TYPE, METHOD})
@Retention(RetentionPolicy.RUNTIME)
+@Deprecated
public @interface MinSdkVersion {
/**
* The minimum required SDK version.
diff --git a/src/io/appium/droiddriver/runner/TestRunner.java b/src/io/appium/droiddriver/runner/TestRunner.java
index 71bb744..e3fbe79 100644
--- a/src/io/appium/droiddriver/runner/TestRunner.java
+++ b/src/io/appium/droiddriver/runner/TestRunner.java
@@ -44,7 +44,10 @@ import io.appium.droiddriver.util.Logs;
/**
* Adds activity watcher to InstrumentationTestRunner.
+ *
+ * @deprecated Use android.support.test.runner.AndroidJUnitRunner instead.
*/
+@Deprecated
public class TestRunner extends InstrumentationTestRunner {
private final Set<Activity> activities = new HashSet<Activity>();
private final AndroidTestRunner androidTestRunner = new AndroidTestRunner();
diff --git a/src/io/appium/droiddriver/runner/UseUiAutomation.java b/src/io/appium/droiddriver/runner/UseUiAutomation.java
index 66ef880..5ba97ef 100644
--- a/src/io/appium/droiddriver/runner/UseUiAutomation.java
+++ b/src/io/appium/droiddriver/runner/UseUiAutomation.java
@@ -33,9 +33,12 @@ import java.lang.annotation.Target;
* As any annotations, it is useful only if it is processed by tools.
* {@link TestRunner} filters out tests with this annotation if the current
* device has SDK version below 18 (JELLY_BEAN_MR2).
+ *
+ * @deprecated Use android.support.test.filters.SdkSuppress instead.
*/
@Inherited
@Target({TYPE, METHOD})
@Retention(RetentionPolicy.RUNTIME)
+@Deprecated
public @interface UseUiAutomation {
}
diff --git a/src/io/appium/droiddriver/util/ActivityUtils.java b/src/io/appium/droiddriver/util/ActivityUtils.java
index 248f6b3..ff06ab5 100644
--- a/src/io/appium/droiddriver/util/ActivityUtils.java
+++ b/src/io/appium/droiddriver/util/ActivityUtils.java
@@ -17,37 +17,54 @@
package io.appium.droiddriver.util;
import android.app.Activity;
-import io.appium.droiddriver.exceptions.UnrecoverableException;
+import android.os.Looper;
+import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
+import android.support.test.runner.lifecycle.Stage;
+import android.util.Log;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
-/**
- * Static helper methods for retrieving activities.
- */
+/** Static helper methods for retrieving activities. */
public class ActivityUtils {
- public interface Supplier<T> {
- /**
- * Retrieves an instance of the appropriate type. The returned object may or
- * may not be a new instance, depending on the implementation.
- *
- * @return an instance of the appropriate type
- */
- T get();
- }
+ private static final Callable<Activity> GET_RUNNING_ACTIVITY =
+ new Callable<Activity>() {
+ @Override
+ public Activity call() {
+ Iterator<Activity> activityIterator =
+ ActivityLifecycleMonitorRegistry.getInstance()
+ .getActivitiesInStage(Stage.RESUMED)
+ .iterator();
+ return activityIterator.hasNext() ? activityIterator.next() : null;
+ }
+ };
+ private static Supplier<Activity> runningActivitySupplier =
+ new Supplier<Activity>() {
+ @Override
+ public Activity get() {
+ try {
+ // If this is called on main (UI) thread, don't call runOnMainSync
+ if (Looper.myLooper() == Looper.getMainLooper()) {
+ return GET_RUNNING_ACTIVITY.call();
+ }
- private static Supplier<Activity> runningActivitySupplier;
+ return InstrumentationUtils.runOnMainSyncWithTimeout(GET_RUNNING_ACTIVITY);
+ } catch (Exception e) {
+ Logs.log(Log.WARN, e);
+ return null;
+ }
+ }
+ };
/**
- * Sets the Supplier for the running (a.k.a. resumed or foreground) activity.
- * Called from {@link io.appium.droiddriver.runner.TestRunner}. If a
- * custom runner is used, this method must be called appropriately, otherwise
- * {@link #getRunningActivity} won't work.
+ * Sets the Supplier for the running (a.k.a. resumed or foreground) activity. If a custom runner
+ * is used, this method must be called appropriately, otherwise {@link #getRunningActivity} won't
+ * work.
*/
public static synchronized void setRunningActivitySupplier(Supplier<Activity> activitySupplier) {
- runningActivitySupplier = activitySupplier;
+ runningActivitySupplier = Preconditions.checkNotNull(activitySupplier);
}
- /**
- * Shorthand to {@link #getRunningActivity(long)} with {@code timeoutMillis=30_000}.
- */
+ /** Shorthand to {@link #getRunningActivity(long)} with {@code timeoutMillis=30_000}. */
public static Activity getRunningActivity() {
return getRunningActivity(30_000L);
}
@@ -74,11 +91,16 @@ public class ActivityUtils {
* @return the currently running activity, or null if no activity has focus.
*/
public static synchronized Activity getRunningActivityNoWait() {
- if (runningActivitySupplier == null) {
- throw new UnrecoverableException(
- "If you don't use DroidDriver TestRunner, you need to call"
- + " ActivityUtils.setRunningActivitySupplier appropriately");
- }
return runningActivitySupplier.get();
}
+
+ public interface Supplier<T> {
+ /**
+ * Retrieves an instance of the appropriate type. The returned object may or may not be a new
+ * instance, depending on the implementation.
+ *
+ * @return an instance of the appropriate type
+ */
+ T get();
+ }
}
diff --git a/src/io/appium/droiddriver/util/InstrumentationUtils.java b/src/io/appium/droiddriver/util/InstrumentationUtils.java
index 0ca087a..06ac5ab 100644
--- a/src/io/appium/droiddriver/util/InstrumentationUtils.java
+++ b/src/io/appium/droiddriver/util/InstrumentationUtils.java
@@ -20,10 +20,10 @@ import android.app.Instrumentation;
import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
+import android.support.test.InstrumentationRegistry;
import android.util.Log;
import io.appium.droiddriver.exceptions.DroidDriverException;
import io.appium.droiddriver.exceptions.TimeoutException;
-import io.appium.droiddriver.exceptions.UnrecoverableException;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -43,11 +43,11 @@ public class InstrumentationUtils {
private static long runOnMainSyncTimeoutMillis;
/**
- * Initializes this class. If you use a runner that is not DroidDriver-aware, you need to call
- * this method appropriately. See {@link io.appium.droiddriver.runner.TestRunner#onCreate} for
- * example.
+ * Initializes this class. If you don't use android.support.test.runner.AndroidJUnitRunner or a
+ * runner that supports {link InstrumentationRegistry}, you need to call this method
+ * appropriately.
*/
- public static void init(Instrumentation instrumentation, Bundle arguments) {
+ public static synchronized void init(Instrumentation instrumentation, Bundle arguments) {
if (InstrumentationUtils.instrumentation != null) {
throw new DroidDriverException("init() can only be called once");
}
@@ -55,14 +55,13 @@ public class InstrumentationUtils {
options = arguments;
String timeoutString = getD2Option("runOnMainSyncTimeout");
- runOnMainSyncTimeoutMillis = timeoutString == null ? 10000L : Long.parseLong(timeoutString);
+ runOnMainSyncTimeoutMillis = timeoutString == null ? 10_000L : Long.parseLong(timeoutString);
}
- private static void checkInitialized() {
+ private static synchronized void checkInitialized() {
if (instrumentation == null) {
- throw new UnrecoverableException(
- "If you use a runner that is not DroidDriver-aware, you"
- + " need to call InstrumentationUtils.init appropriately");
+ // Assume android.support.test.runner.InstrumentationRegistry is valid
+ init(InstrumentationRegistry.getInstrumentation(), InstrumentationRegistry.getArguments());
}
}
@@ -85,11 +84,7 @@ public class InstrumentationUtils {
return options;
}
- /**
- * Gets the string value associated with the given key. This is preferred over using {@link
- * #getOptions} because the returned {@link Bundle} contains only string values - am instrument
- * options do not support value types other than string.
- */
+ /** Gets the string value associated with the given key. */
public static String getOption(String key) {
return getOptions().getString(key);
}
@@ -110,7 +105,7 @@ public class InstrumentationUtils {
public static boolean tryWaitForIdleSync(long timeoutMillis) {
checkNotMainThread();
FutureTask<Void> emptyTask = new FutureTask<Void>(EMPTY_RUNNABLE, null);
- instrumentation.waitForIdle(emptyTask);
+ getInstrumentation().waitForIdle(emptyTask);
try {
emptyTask.get(timeoutMillis, TimeUnit.MILLISECONDS);