diff options
author | Kevin Jin <kjin@google.com> | 2015-02-23 22:44:56 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-02-23 22:44:56 +0000 |
commit | 8958e52281d21824bcf3a4ecd764b0dedd6b1a9f (patch) | |
tree | 0a4a6d976ca45f3b87433927d57d50cb3cd51b41 /src/io/appium/droiddriver/helpers/PollingListeners.java | |
parent | 83428e1c03587f33d4f729573a4a68172bcf50a1 (diff) | |
parent | 20ed14a213a5fe6a59a60a445de361a720ce2532 (diff) | |
download | droiddriver-8958e52281d21824bcf3a4ecd764b0dedd6b1a9f.tar.gz |
am 20ed14a2: Merge "rename package \'com.google.android\' to \'io.appium\'"
* commit '20ed14a213a5fe6a59a60a445de361a720ce2532':
rename package 'com.google.android' to 'io.appium'
Diffstat (limited to 'src/io/appium/droiddriver/helpers/PollingListeners.java')
-rw-r--r-- | src/io/appium/droiddriver/helpers/PollingListeners.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/io/appium/droiddriver/helpers/PollingListeners.java b/src/io/appium/droiddriver/helpers/PollingListeners.java new file mode 100644 index 0000000..2508fdf --- /dev/null +++ b/src/io/appium/droiddriver/helpers/PollingListeners.java @@ -0,0 +1,56 @@ +package io.appium.droiddriver.helpers; + +import io.appium.droiddriver.DroidDriver; +import io.appium.droiddriver.Poller.PollingListener; +import io.appium.droiddriver.exceptions.ElementNotFoundException; +import io.appium.droiddriver.finders.Finder; + +/** + * Static utility methods to create commonly used PollingListeners. + */ +public class PollingListeners { + /** + * Tries to find {@code watchFinder}, and clicks it if found. + * + * @param driver a DroidDriver instance + * @param watchFinder Identifies the UI component to watch + * @return whether {@code watchFinder} is found + */ + public static boolean tryFindAndClick(DroidDriver driver, Finder watchFinder) { + try { + driver.find(watchFinder).click(); + return true; + } catch (ElementNotFoundException enfe) { + return false; + } + } + + /** + * 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 (driver.has(watchFinder)) { + driver.find(dismissFinder).click(); + } + } + }; + } + + private PollingListeners() {} +} |