@Override public void perform(UiController uiController, View view) { uiController.loopMainThreadForAtLeast(1000); uiController.loopMainThreadUntilIdle(); } });
@Override public void perform(UiController uiController, View view) { uiController.loopMainThreadForAtLeast(millis); } };
@Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); ((MovieView) view).showControls(); uiController.loopMainThreadUntilIdle(); } };
@Override public void perform(UiController uiController, final View view) { uiController.loopMainThreadForAtLeast(millis); } };
@Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); ((MovieView) view).showControls(); uiController.loopMainThreadUntilIdle(); } };
@Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); final long endTime = System.currentTimeMillis() + millis; do { for (View child : TreeIterables.breadthFirstViewTraversal(view)) { if (child.getId() == viewId) { if (checkStatus.check(child)) { return; } } } uiController.loopMainThreadForAtLeast(50); } while (System.currentTimeMillis() < endTime); throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause(new TimeoutException()) .build(); } };
@Override public void perform(UiController uiController, final View view) { uiController.loopMainThreadForAtLeast(millis); } };
@Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); int orientation = getActivityOrientation(view); boolean checkOrientation = false; switch (orientationType) { case PORTRAIT: checkOrientation = orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT; break; case LANDSCAPE: checkOrientation = orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE; break; } if (checkOrientation) { isOrientation[0] = true; } } }
@Override public void perform(UiController uiController, View view) { final Activity activity = EspressoTestBase.currentActivity(); // change rotation programmatically ignores android manifest configurations if (hasActivityFixedOrientation(activity)) { return; } activity.setRequestedOrientation(requestedOrientation); // wait until rotation is done, espresso checks and actions don't wait // sometimes activity is not rotated when next check or action is performed int requestedOrientation = this.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT; while (InstrumentationRegistry.getContext().getResources().getConfiguration().orientation != requestedOrientation) { uiController.loopMainThreadForAtLeast(30); } }
@Override public void perform(UiController uiController, View view) { if (isDisplayingAtLeast(90).matches(view)) { Log.i(TAG, "View is already displayed. Returning."); return; } Rect rect = new Rect(); view.getDrawingRect(rect); if (!view.requestRectangleOnScreen(rect, true /* immediate */)) { Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled."); } uiController.loopMainThreadUntilIdle(); if (!isDisplayingAtLeast(90).matches(view)) { throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause(new RuntimeException( "Scrolling to view was attempted, but the view is not displayed")) .build(); } }
@Override public void perform(UiController uiController, View view) { SeekBar seekBar = (SeekBar) view; int[] seekBarPos = {0,0}; view.getLocationOnScreen(seekBarPos); float[] startPos = {seekBarPos[0], seekBarPos[1]}; MotionEvents.DownResultHolder downResultHolder = MotionEvents.sendDown(uiController, startPos, Press.PINPOINT.describePrecision()); while(seekBar.getProgress() < progress) { startPos[0]++; MotionEvents.sendMovement(uiController, downResultHolder.down, startPos); uiController.loopMainThreadForAtLeast(10); } MotionEvents.sendUp(uiController, downResultHolder.down, startPos); } };
@Override public void perform(UiController uiController, View view) { if (isDisplayingAtLeast(90).matches(view)) { LogUtils.LOGI(TAG, "View is already displayed. Returning."); return; } Rect rect = new Rect(); view.getDrawingRect(rect); if (!view.requestRectangleOnScreen(rect, true /* immediate */)) { LogUtils.LOGW(TAG, "Scrolling to view was requested, but none of the parents scrolled."); } uiController.loopMainThreadUntilIdle(); if (!isDisplayingAtLeast(90).matches(view)) { throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause(new RuntimeException( "Scrolling to view was attempted, but the view is not displayed")) .build(); } } }
@Override public Status sendSwipe(UiController uiController, float[] startCoordinates, float[] endCoordinates, float[] precision) { final float[][] steps = interpolate(startCoordinates, endCoordinates, STEPS); final int delayBetweenMovements = DURATION / steps.length; MotionEvent downEvent = MotionEvents.sendDown(uiController, startCoordinates, precision).down; try { for (int i = 0; i < steps.length; i++) { MotionEvents.sendMovement(uiController, downEvent, steps[i]); long desiredTime = downEvent.getDownTime() + delayBetweenMovements * i; long timeUntilDesired = desiredTime - SystemClock.uptimeMillis(); if (timeUntilDesired > 10) { uiController.loopMainThreadForAtLeast(timeUntilDesired); } } MotionEvents.sendUp(uiController, downEvent, endCoordinates); } finally { downEvent.recycle(); } return Status.SUCCESS; } };
@Override public Status sendTap( UiController uiController, float[] coordinates, float[] precision, int inputDevice, int buttonState) { MotionEvent downEvent = MotionEvents.sendDown(uiController, coordinates, precision, inputDevice, buttonState).down; try { // Duration before a press turns into a long press. // Factor 1.5 is needed, otherwise a long press is not safely detected. // See android.test.TouchUtils longClickView long longPressTimeout = (long) (this.longPressTimeout * 1.5f); uiController.loopMainThreadForAtLeast(longPressTimeout); if (!MotionEvents.sendUp(uiController, downEvent)) { MotionEvents.sendCancel(uiController, downEvent); return Status.FAILURE; } } finally { downEvent.recycle(); } return Status.SUCCESS; }