/** * Scrolls up and down. * * @param direction the direction in which to scroll * @param allTheWay <code>true</code> if the view should be scrolled to the beginning or end, * <code>false</code> to scroll one page up or down. * @return {@code true} if more scrolling can be done */ public boolean scroll(int direction, boolean allTheWay) { final ArrayList<View> viewList = RobotiumUtils.removeInvisibleViews(viewFetcher.getAllViews(true)); @SuppressWarnings("unchecked") ArrayList<View> views = RobotiumUtils.filterViewsToSet( new Class[] {ListView.class, ScrollView.class, GridView.class, WebView.class}, viewList); View view = viewFetcher.getFreshestView(views); if (view == null) { view = viewFetcher.getRecyclerView(0); if (view == null) { return false; } } if (view instanceof AbsListView) { return scrollList((AbsListView) view, direction, allTheWay); } if (view instanceof WebView) { return scrollWebView((WebView) view, direction, allTheWay); } if (allTheWay) { scrollViewAllTheWay(view, direction); return false; } else { return scrollView(view, direction); } }
public boolean scrollEx(int direction, boolean allTheWay, View scroll) { View parent = this.getTopFrame(); final ArrayList<View> viewList = RobotiumUtils.removeInvisibleViews(viewFetcher.getViews(parent, true)); @SuppressWarnings("unchecked") ArrayList<View> views = RobotiumUtils.filterViewsToSet( new Class[] {ListView.class, ScrollView.class, GridView.class, WebView.class}, viewList); View view = viewFetcher.getFreshestView(views); if (scroll != null) view = scroll; // LogEx.i("scroller: "+view); if (view == null) { return false; } if (view instanceof AbsListView) { return scroller.scrollList((AbsListView) view, direction, allTheWay); } if (view instanceof ScrollView) { if (allTheWay) { scroller.scrollViewAllTheWay((ScrollView) view, direction); return false; } else { return scroller.scrollView((ScrollView) view, direction); } } if (view instanceof WebView) { return scroller.scrollWebView((WebView) view, direction, allTheWay); } return false; }
/** * Waits for and returns a View. * * @param index the index of the view * @param classToFilterby the class to filter * @return the specified View */ public <T extends View> T waitForAndGetView(int index, Class<T> classToFilterBy) { long endTime = SystemClock.uptimeMillis() + Timeout.getSmallTimeout(); while (SystemClock.uptimeMillis() <= endTime && !waitForView(classToFilterBy, index, true, true)) ; int numberOfUniqueViews = searcher.getNumberOfUniqueViews(); ArrayList<T> views = RobotiumUtils.removeInvisibleViews(viewFetcher.getCurrentViews(classToFilterBy)); if (views.size() < numberOfUniqueViews) { int newIndex = index - (numberOfUniqueViews - views.size()); if (newIndex >= 0) index = newIndex; } T view = null; try { view = views.get(index); } catch (IndexOutOfBoundsException exception) { int match = index + 1; if (match > 1) { Assert.fail(match + " " + classToFilterBy.getSimpleName() + "s" + " are not found!"); } else { Assert.fail(classToFilterBy.getSimpleName() + " is not found!"); } } views = null; return view; }