• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 android.util.Log;
20 
21 import io.appium.droiddriver.UiElement;
22 import io.appium.droiddriver.finders.ByXPath;
23 import io.appium.droiddriver.finders.Finder;
24 import io.appium.droiddriver.util.Logs;
25 
26 /**
27  * Enhances AbstractDroidDriver to include basic element handling and matching operations.
28  */
29 public abstract class BaseDroidDriver<R, E extends BaseUiElement<R, E>> extends AbstractDroidDriver {
30 
31   private E rootElement;
32 
33   @Override
find(Finder finder)34   public UiElement find(Finder finder) {
35     Logs.call(Log.VERBOSE, this, "find", finder);
36     return finder.find(getRootElement());
37   }
38 
newRootElement()39   protected abstract E newRootElement();
40 
41   /**
42    * Returns a new UiElement of type {@code E}.
43    */
newUiElement(R rawElement, E parent)44   protected abstract E newUiElement(R rawElement, E parent);
45 
getRootElement()46   public E getRootElement() {
47     if (rootElement == null) {
48       refreshUiElementTree();
49     }
50     return rootElement;
51   }
52 
53   @Override
refreshUiElementTree()54   public void refreshUiElementTree() {
55     rootElement = newRootElement();
56   }
57 
58   @Override
dumpUiElementTree(String path)59   public boolean dumpUiElementTree(String path) {
60     Logs.call(this, "dumpUiElementTree", path);
61     return ByXPath.dumpDom(path, getRootElement());
62   }
63 }
64