• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 DroidDriver committers
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.appium.droiddriver.base;
18 
19 import io.appium.droiddriver.DroidDriver;
20 import io.appium.droiddriver.Poller;
21 import io.appium.droiddriver.UiElement;
22 import io.appium.droiddriver.actions.InputInjector;
23 import io.appium.droiddriver.exceptions.ElementNotFoundException;
24 import io.appium.droiddriver.exceptions.TimeoutException;
25 import io.appium.droiddriver.finders.Finder;
26 import io.appium.droiddriver.util.Logs;
27 
28 /**
29  * Base DroidDriver that implements the common operations.
30  */
31 public abstract class AbstractDroidDriver implements DroidDriver {
32 
33   private Poller poller = new DefaultPoller();
34 
35   @Override
has(Finder finder)36   public boolean has(Finder finder) {
37     try {
38       refreshUiElementTree();
39       find(finder);
40       return true;
41     } catch (ElementNotFoundException enfe) {
42       return false;
43     }
44   }
45 
46   @Override
has(Finder finder, long timeoutMillis)47   public boolean has(Finder finder, long timeoutMillis) {
48     try {
49       getPoller().pollFor(this, finder, Poller.EXISTS, timeoutMillis);
50       return true;
51     } catch (TimeoutException e) {
52       return false;
53     }
54   }
55 
56   @Override
on(Finder finder)57   public UiElement on(Finder finder) {
58     Logs.call(this, "on", finder);
59     return getPoller().pollFor(this, finder, Poller.EXISTS);
60   }
61 
62   @Override
checkExists(Finder finder)63   public void checkExists(Finder finder) {
64     Logs.call(this, "checkExists", finder);
65     getPoller().pollFor(this, finder, Poller.EXISTS);
66   }
67 
68   @Override
checkGone(Finder finder)69   public void checkGone(Finder finder) {
70     Logs.call(this, "checkGone", finder);
71     getPoller().pollFor(this, finder, Poller.GONE);
72   }
73 
74   @Override
getPoller()75   public Poller getPoller() {
76     return poller;
77   }
78 
79   @Override
setPoller(Poller poller)80   public void setPoller(Poller poller) {
81     this.poller = poller;
82   }
83 
getInjector()84   public abstract InputInjector getInjector();
85 
86 }