aboutsummaryrefslogtreecommitdiff
path: root/src/io/appium/droiddriver/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/appium/droiddriver/base')
-rw-r--r--src/io/appium/droiddriver/base/AbstractDroidDriver.java86
-rw-r--r--src/io/appium/droiddriver/base/BaseDroidDriver.java62
-rw-r--r--src/io/appium/droiddriver/base/CompositeDroidDriver.java59
3 files changed, 147 insertions, 60 deletions
diff --git a/src/io/appium/droiddriver/base/AbstractDroidDriver.java b/src/io/appium/droiddriver/base/AbstractDroidDriver.java
new file mode 100644
index 0000000..bf0df4b
--- /dev/null
+++ b/src/io/appium/droiddriver/base/AbstractDroidDriver.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2016 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.base;
+
+import io.appium.droiddriver.DroidDriver;
+import io.appium.droiddriver.Poller;
+import io.appium.droiddriver.UiElement;
+import io.appium.droiddriver.actions.InputInjector;
+import io.appium.droiddriver.exceptions.ElementNotFoundException;
+import io.appium.droiddriver.exceptions.TimeoutException;
+import io.appium.droiddriver.finders.Finder;
+import io.appium.droiddriver.util.Logs;
+
+/**
+ * Base DroidDriver that implements the common operations.
+ */
+public abstract class AbstractDroidDriver implements DroidDriver {
+
+ private Poller poller = new DefaultPoller();
+
+ @Override
+ public boolean has(Finder finder) {
+ try {
+ refreshUiElementTree();
+ find(finder);
+ return true;
+ } catch (ElementNotFoundException enfe) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean has(Finder finder, long timeoutMillis) {
+ try {
+ getPoller().pollFor(this, finder, Poller.EXISTS, timeoutMillis);
+ return true;
+ } catch (TimeoutException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public UiElement on(Finder finder) {
+ Logs.call(this, "on", finder);
+ return getPoller().pollFor(this, finder, Poller.EXISTS);
+ }
+
+ @Override
+ public void checkExists(Finder finder) {
+ Logs.call(this, "checkExists", finder);
+ getPoller().pollFor(this, finder, Poller.EXISTS);
+ }
+
+ @Override
+ public void checkGone(Finder finder) {
+ Logs.call(this, "checkGone", finder);
+ getPoller().pollFor(this, finder, Poller.GONE);
+ }
+
+ @Override
+ public Poller getPoller() {
+ return poller;
+ }
+
+ @Override
+ public void setPoller(Poller poller) {
+ this.poller = poller;
+ }
+
+ public abstract InputInjector getInjector();
+
+} \ No newline at end of file
diff --git a/src/io/appium/droiddriver/base/BaseDroidDriver.java b/src/io/appium/droiddriver/base/BaseDroidDriver.java
index e985a38..827bce6 100644
--- a/src/io/appium/droiddriver/base/BaseDroidDriver.java
+++ b/src/io/appium/droiddriver/base/BaseDroidDriver.java
@@ -17,23 +17,16 @@
package io.appium.droiddriver.base;
import android.util.Log;
-
-import io.appium.droiddriver.DroidDriver;
-import io.appium.droiddriver.Poller;
import io.appium.droiddriver.UiElement;
-import io.appium.droiddriver.actions.InputInjector;
-import io.appium.droiddriver.exceptions.ElementNotFoundException;
-import io.appium.droiddriver.exceptions.TimeoutException;
import io.appium.droiddriver.finders.ByXPath;
import io.appium.droiddriver.finders.Finder;
import io.appium.droiddriver.util.Logs;
/**
- * Base DroidDriver that implements the common operations.
+ * Enhances AbstractDroidDriver to include basic element handling and matching operations.
*/
-public abstract class BaseDroidDriver<R, E extends BaseUiElement<R, E>> implements DroidDriver {
+public abstract class BaseDroidDriver<R, E extends BaseUiElement<R, E>> extends AbstractDroidDriver {
- private Poller poller = new DefaultPoller();
private E rootElement;
@Override
@@ -42,57 +35,6 @@ public abstract class BaseDroidDriver<R, E extends BaseUiElement<R, E>> implemen
return finder.find(getRootElement());
}
- @Override
- public boolean has(Finder finder) {
- try {
- refreshUiElementTree();
- find(finder);
- return true;
- } catch (ElementNotFoundException enfe) {
- return false;
- }
- }
-
- @Override
- public boolean has(Finder finder, long timeoutMillis) {
- try {
- getPoller().pollFor(this, finder, Poller.EXISTS, timeoutMillis);
- return true;
- } catch (TimeoutException e) {
- return false;
- }
- }
-
- @Override
- public UiElement on(Finder finder) {
- Logs.call(this, "on", finder);
- return getPoller().pollFor(this, finder, Poller.EXISTS);
- }
-
- @Override
- public void checkExists(Finder finder) {
- Logs.call(this, "checkExists", finder);
- getPoller().pollFor(this, finder, Poller.EXISTS);
- }
-
- @Override
- public void checkGone(Finder finder) {
- Logs.call(this, "checkGone", finder);
- getPoller().pollFor(this, finder, Poller.GONE);
- }
-
- @Override
- public Poller getPoller() {
- return poller;
- }
-
- @Override
- public void setPoller(Poller poller) {
- this.poller = poller;
- }
-
- public abstract InputInjector getInjector();
-
protected abstract E newRootElement();
/**
diff --git a/src/io/appium/droiddriver/base/CompositeDroidDriver.java b/src/io/appium/droiddriver/base/CompositeDroidDriver.java
new file mode 100644
index 0000000..c92c5c3
--- /dev/null
+++ b/src/io/appium/droiddriver/base/CompositeDroidDriver.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2016 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.base;
+
+import io.appium.droiddriver.UiDevice;
+import io.appium.droiddriver.UiElement;
+import io.appium.droiddriver.actions.InputInjector;
+import io.appium.droiddriver.finders.Finder;
+
+/**
+ * Helper class to ease creation of drivers that defer actions to other drivers.
+ */
+public abstract class CompositeDroidDriver extends AbstractDroidDriver {
+ /**
+ * Determines which DroidDriver should handle the current situation.
+ *
+ * @return The DroidDriver instance to use
+ */
+ protected abstract AbstractDroidDriver getApplicableDriver();
+
+ @Override
+ public InputInjector getInjector() {
+ return getApplicableDriver().getInjector();
+ }
+
+ @Override
+ public UiDevice getUiDevice() {
+ return getApplicableDriver().getUiDevice();
+ }
+
+ @Override
+ public UiElement find(Finder finder) {
+ return getApplicableDriver().find(finder);
+ }
+
+ @Override
+ public void refreshUiElementTree() {
+ getApplicableDriver().refreshUiElementTree();
+ }
+
+ @Override
+ public boolean dumpUiElementTree(String path) {
+ return getApplicableDriver().dumpUiElementTree(path);
+ }
+}