@Test public void itFindsTheRoot() { ViewGroup root = match(); List<View> views = searchViews(root); assertFoundViews(views, root); }
protected static List<AndroidElement> searchViews(AbstractNativeElementContext context, View root, Predicate predicate, boolean findJustOne) { List<AndroidElement> elements = new ArrayList<AndroidElement>(); if (root == null) { return elements; } ArrayDeque<View> queue = new ArrayDeque<View>(); queue.add(root); while (!queue.isEmpty()) { View view = queue.pop(); if (predicate.apply(view)) { elements.add(context.newAndroidElement(view)); if (findJustOne) { break; } } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int childrenCount = group.getChildCount(); for (int index = 0; index < childrenCount; index++) { queue.add(group.getChildAt(index)); } } } return elements; }
AbstractNativeElementContext implements
      SearchContext,
      FindsByTagName,
      FindsByName,
      FindsById,
      FindsByText,
      FindsByXPath,
      FindsByPartialText,
      FindsByClass { protected static List<AndroidElement> searchViews(AbstractNativeElementContext context, View root, Predicate predicate, boolean findJustOne) { List<AndroidElement> elements = new ArrayList<AndroidElement>(); if (root == null) { return elements; } ArrayDeque<View> queue = new ArrayDeque<View>(); queue.add(root); while (!queue.isEmpty()) { View view = queue.pop(); if (predicate.apply(view)) { elements.add(context.newAndroidElement(view)); if (findJustOne) { break; } } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int childrenCount = group.getChildCount(); for (int index = 0; index < childrenCount; index++) { queue.add(group.getChildAt(index)); } } } return elements; } }
AbstractNativeElementContext implements
      SearchContext,
      FindsByTagName,
      FindsByName,
      FindsById,
      FindsByText,
      FindsByXPath,
      FindsByPartialText,
      FindsByClass { protected static List<AndroidElement> searchViews(AbstractNativeElementContext context, View root, Predicate predicate, boolean findJustOne) { List<AndroidElement> elements = new ArrayList<AndroidElement>(); if (root == null) { return elements; } ArrayDeque<View> queue = new ArrayDeque<View>(); queue.add(root); while (!queue.isEmpty()) { View view = queue.pop(); if (predicate.apply(view)) { elements.add(context.newAndroidElement(view)); if (findJustOne) { break; } } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int childrenCount = group.getChildCount(); for (int index = 0; index < childrenCount; index++) { queue.add(group.getChildAt(index)); } } } return elements; } AbstractNativeElementContext(ServerInstrumentation instrumentation, KeySender keys, KnownElements knownElements); }
AbstractNativeElementContext implements
      SearchContext,
      FindsByTagName,
      FindsByName,
      FindsById,
      FindsByText,
      FindsByXPath,
      FindsByPartialText,
      FindsByClass { protected static List<AndroidElement> searchViews(AbstractNativeElementContext context, View root, Predicate predicate, boolean findJustOne) { List<AndroidElement> elements = new ArrayList<AndroidElement>(); if (root == null) { return elements; } ArrayDeque<View> queue = new ArrayDeque<View>(); queue.add(root); while (!queue.isEmpty()) { View view = queue.pop(); if (predicate.apply(view)) { elements.add(context.newAndroidElement(view)); if (findJustOne) { break; } } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int childrenCount = group.getChildCount(); for (int index = 0; index < childrenCount; index++) { queue.add(group.getChildAt(index)); } } } return elements; } AbstractNativeElementContext(ServerInstrumentation instrumentation, KeySender keys, KnownElements knownElements); JSONObject getElementTree(); @Override List<AndroidElement> findElements(By by); @Override AndroidElement findElement(By by); AndroidElement findElementByXPath(String using); List<AndroidElement> findElementsByXPath(String expression); @Override AndroidElement findElementById(String using); @Override List<AndroidElement> findElementsById(String using); @Override AndroidElement findElementByName(String using); @Override List<AndroidElement> findElementsByName(String using); @Override AndroidElement findElementByTagName(String using); @Override List<AndroidElement> findElementsByTagName(String using); @Override AndroidElement findElementByText(String using); @Override List<AndroidElement> findElementsByText(String using); @Override AndroidElement findElementByPartialText(String using); @Override List<AndroidElement> findElementsByPartialText(String using); @Override AndroidElement findElementByClass(String using); @Override List<AndroidElement> findElementsByClass(String using); }
AbstractNativeElementContext implements
      SearchContext,
      FindsByTagName,
      FindsByName,
      FindsById,
      FindsByText,
      FindsByXPath,
      FindsByPartialText,
      FindsByClass { protected static List<AndroidElement> searchViews(AbstractNativeElementContext context, View root, Predicate predicate, boolean findJustOne) { List<AndroidElement> elements = new ArrayList<AndroidElement>(); if (root == null) { return elements; } ArrayDeque<View> queue = new ArrayDeque<View>(); queue.add(root); while (!queue.isEmpty()) { View view = queue.pop(); if (predicate.apply(view)) { elements.add(context.newAndroidElement(view)); if (findJustOne) { break; } } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int childrenCount = group.getChildCount(); for (int index = 0; index < childrenCount; index++) { queue.add(group.getChildAt(index)); } } } return elements; } AbstractNativeElementContext(ServerInstrumentation instrumentation, KeySender keys, KnownElements knownElements); JSONObject getElementTree(); @Override List<AndroidElement> findElements(By by); @Override AndroidElement findElement(By by); AndroidElement findElementByXPath(String using); List<AndroidElement> findElementsByXPath(String expression); @Override AndroidElement findElementById(String using); @Override List<AndroidElement> findElementsById(String using); @Override AndroidElement findElementByName(String using); @Override List<AndroidElement> findElementsByName(String using); @Override AndroidElement findElementByTagName(String using); @Override List<AndroidElement> findElementsByTagName(String using); @Override AndroidElement findElementByText(String using); @Override List<AndroidElement> findElementsByText(String using); @Override AndroidElement findElementByPartialText(String using); @Override List<AndroidElement> findElementsByPartialText(String using); @Override AndroidElement findElementByClass(String using); @Override List<AndroidElement> findElementsByClass(String using);  }