aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Jin <kjin@google.com>2013-12-12 16:20:36 -0800
committerKevin Jin <kjin@google.com>2013-12-12 16:20:36 -0800
commit7655a5e140a667493d177b3e19d3ee415e97d43b (patch)
treeb2760d1eebaef2bfb5a63dd6bc0f4440d72d2a21 /src
parent9031ed9b636ccd3b942eefb85dbfae2aed9e4f11 (diff)
downloaddroiddriver-7655a5e140a667493d177b3e19d3ee415e97d43b.tar.gz
add helpers/PollingListeners
remove reference to newIdentityHashSet so that DroidDriver works with older Guava Change-Id: Ia7bb1f564c7764f43cfcafa0ad59ce1fa481f3d1
Diffstat (limited to 'src')
-rw-r--r--src/com/google/android/droiddriver/helpers/PollingListeners.java49
-rw-r--r--src/com/google/android/droiddriver/runner/TestRunner.java2
2 files changed, 50 insertions, 1 deletions
diff --git a/src/com/google/android/droiddriver/helpers/PollingListeners.java b/src/com/google/android/droiddriver/helpers/PollingListeners.java
new file mode 100644
index 0000000..768ea88
--- /dev/null
+++ b/src/com/google/android/droiddriver/helpers/PollingListeners.java
@@ -0,0 +1,49 @@
+package com.google.android.droiddriver.helpers;
+
+import com.google.android.droiddriver.DroidDriver;
+import com.google.android.droiddriver.Poller.PollingListener;
+import com.google.android.droiddriver.UiElement;
+import com.google.android.droiddriver.exceptions.ElementNotFoundException;
+import com.google.android.droiddriver.finders.Finder;
+
+/**
+ * Static utility methods to create commonly used PollingListeners.
+ */
+public class PollingListeners {
+ private static UiElement tryFind(DroidDriver driver, Finder finder) {
+ try {
+ return driver.find(finder);
+ } catch (ElementNotFoundException enfe) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns a new {@code PollingListener} that will look for
+ * {@code watchFinder}, then click {@code dismissFinder} to dismiss it.
+ * <p>
+ * Typically a {@code PollingListener} is used to dismiss "random" dialogs. If
+ * you know the certain situation when a dialog is displayed, you should deal
+ * with the dialog in the specific situation instead of using a
+ * {@code PollingListener} because it is checked in all polling events, which
+ * occur frequently.
+ * </p>
+ *
+ * @param watchFinder Identifies the UI component, for example an AlertDialog
+ * @param dismissFinder Identifies the UiElement to click on that will dismiss
+ * the UI component
+ */
+ public static PollingListener newDismissListener(final Finder watchFinder,
+ final Finder dismissFinder) {
+ return new PollingListener() {
+ @Override
+ public void onPolling(DroidDriver driver, Finder finder) {
+ if (tryFind(driver, watchFinder) != null) {
+ driver.find(dismissFinder).click();
+ }
+ }
+ };
+ }
+
+ private PollingListeners() {}
+}
diff --git a/src/com/google/android/droiddriver/runner/TestRunner.java b/src/com/google/android/droiddriver/runner/TestRunner.java
index 4f83e3e..9b9846e 100644
--- a/src/com/google/android/droiddriver/runner/TestRunner.java
+++ b/src/com/google/android/droiddriver/runner/TestRunner.java
@@ -45,7 +45,7 @@ import java.util.Set;
* Adds activity watcher to InstrumentationTestRunner.
*/
public class TestRunner extends InstrumentationTestRunner {
- private final Set<Activity> activities = Sets.newIdentityHashSet();
+ private final Set<Activity> activities = Sets.newHashSet();
private final AndroidTestRunner androidTestRunner = new AndroidTestRunner();
private Activity runningActivity;