Java Examples for android.support.test.espresso.UiController
The following java examples will help you to understand the usage of android.support.test.espresso.UiController. These source code samples are taken from different open source projects.
Example 1
Project: Barista-master File: PerformClickAction.java View source code |
/** * Common Espresso's ViewActions.click() taps on the center of the View. * But, if that View has a children placed on its center, that child will * be clicked instead of the View itself. * * This Action fixes that behavior, just clicking on the View using its * instance, not its position. */ public static ViewAction clickUsingPerformClick() { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isDisplayed(); } @Override public String getDescription() { return "Click on the view using performClick()"; } @Override public void perform(UiController uiController, View view) { if (view.isClickable()) { view.performClick(); } else { propagateClickToChildren(uiController, view); } } private void propagateClickToChildren(UiController uiController, View view) { click().perform(uiController, view); } }; }
Example 2
Project: ecampus-client-android-master File: OrientationChangeAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
final Activity activity = (Activity) view.getContext();
activity.setRequestedOrientation(orientation);
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
throw new RuntimeException("Could not change orientation");
}
}
Example 3
Project: qualitymatters-master File: ViewActions.java View source code |
@NonNull
public static ViewAction noOp() {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return null;
}
@Override
public String getDescription() {
return "no-op";
}
@Override
public void perform(UiController uiController, View view) {
// no-op
}
};
}
Example 4
Project: FileSpace-Android-master File: DrawerLayoutUtils.java View source code |
public static ViewAction actionOpenDrawer() {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(android.support.v4.widget.DrawerLayout.class);
}
@Override
public String getDescription() {
return "open drawer";
}
@Override
public void perform(UiController uiController, View view) {
((android.support.v4.widget.DrawerLayout) view).openDrawer(GravityCompat.START);
}
};
}
Example 5
Project: 3House-master File: SliderActions.java View source code |
public static ViewAction setProgress(final int progress) {
return new ViewAction() {
@Override
public void perform(UiController uiController, View view) {
SeekBar seekBar = (SeekBar) view;
seekBar.setProgress(progress);
}
@Override
public String getDescription() {
return "Set a progress on a SeekBar";
}
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(SeekBar.class);
}
};
}
Example 6
Project: AndroidSnooper-master File: WaitForViewAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
ViewMatcherIdlingResource idlingResource = new ViewMatcherIdlingResource(timeout, viewMatcher, view);
registerIdlingResources(idlingResource);
uiController.loopMainThreadUntilIdle();
unregisterIdlingResources(idlingResource);
if (!idlingResource.isMatched()) {
throw new PerformException.Builder().withActionDescription(getDescription()).withViewDescription(HumanReadables.getViewHierarchyErrorMessage(view, null, "Action timed out : " + getDescription(), null)).build();
}
}
Example 7
Project: android_frameworks_base-master File: DragAction.java View source code |
@Override
@Nullable
public MotionEvent perform(UiController uiController, float[] coordinates, float[] precision) {
MotionEvent downEvent = MotionEvents.sendDown(uiController, coordinates, precision).down;
for (int i = 0; i < 2; ++i) {
try {
if (!MotionEvents.sendUp(uiController, downEvent)) {
String logMessage = "Injection of up event as part of the triple " + "click failed. Sending cancel event.";
Log.d(TAG, logMessage);
MotionEvents.sendCancel(uiController, downEvent);
return null;
}
long doubleTapMinimumTimeout = ViewConfiguration.getDoubleTapMinTime();
uiController.loopMainThreadForAtLeast(doubleTapMinimumTimeout);
} finally {
downEvent.recycle();
}
downEvent = MotionEvents.sendDown(uiController, coordinates, precision).down;
}
return downEvent;
}
Example 8
Project: cameraview-master File: CameraViewTest.java View source code |
@Test
public void testAdjustViewBounds() {
onView(withId(R.id.camera)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
CameraView cameraView = (CameraView) view;
assertThat(cameraView.getAdjustViewBounds(), is(false));
cameraView.setAdjustViewBounds(true);
assertThat(cameraView.getAdjustViewBounds(), is(true));
}
}).perform(new AnythingAction("layout") {
@Override
public void perform(UiController uiController, View view) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
view.setLayoutParams(params);
}
}).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
CameraView cameraView = (CameraView) view;
AspectRatio cameraRatio = cameraView.getAspectRatio();
AspectRatio viewRatio = AspectRatio.of(view.getWidth(), view.getHeight());
assertThat(cameraRatio, is(closeToOrInverse(viewRatio)));
}
});
}
Example 9
Project: FastHub-master File: TestHelper.java View source code |
public static ViewAction bottomNavAction(@IntRange(from = 0, to = 3) final int index) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(BottomNavigation.class);
}
@Override
public String getDescription() {
return "BottomNavigation";
}
@Override
public void perform(UiController uiController, View view) {
((BottomNavigation) view).setSelectedIndex(index, false);
}
};
}
Example 10
Project: material-components-android-master File: TabLayoutWithViewPagerTest.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
final ViewPager viewPager = (ViewPager) view;
// no way to avoid this cast
@SuppressWarnings("unchecked") final BasePagerAdapter<Q> viewPagerAdapter = (BasePagerAdapter<Q>) viewPager.getAdapter();
viewPagerAdapter.add(title, content);
viewPagerAdapter.notifyDataSetChanged();
uiController.loopMainThreadUntilIdle();
}
Example 11
Project: MultiSlider-master File: SetThumbValueAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
if (value == Integer.MAX_VALUE) {
value = getThumb((MultiSlider) view).getValue() + ((MultiSlider) view).getStep();
} else if (value == Integer.MIN_VALUE) {
value = getThumb((MultiSlider) view).getValue() - ((MultiSlider) view).getStep();
}
getThumb((MultiSlider) view).setValue(value);
}
Example 12
Project: open-keychain-master File: TestHelpers.java View source code |
public static void dismissSnackbar() {
onView(withClassName(endsWith("Snackbar"))).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(Snackbar.class);
}
@Override
public String getDescription() {
return "dismiss snackbar";
}
@Override
public void perform(UiController uiController, View view) {
((Snackbar) view).dismiss();
}
});
}
Example 13
Project: platform_frameworks_base-master File: DragAction.java View source code |
@Override
@Nullable
public MotionEvent perform(UiController uiController, float[] coordinates, float[] precision) {
MotionEvent downEvent = MotionEvents.sendDown(uiController, coordinates, precision).down;
for (int i = 0; i < 2; ++i) {
try {
if (!MotionEvents.sendUp(uiController, downEvent)) {
String logMessage = "Injection of up event as part of the triple " + "click failed. Sending cancel event.";
Log.d(TAG, logMessage);
MotionEvents.sendCancel(uiController, downEvent);
return null;
}
long doubleTapMinimumTimeout = ViewConfiguration.getDoubleTapMinTime();
uiController.loopMainThreadForAtLeast(doubleTapMinimumTimeout);
} finally {
downEvent.recycle();
}
downEvent = MotionEvents.sendDown(uiController, coordinates, precision).down;
}
return downEvent;
}
Example 14
Project: platform_frameworks_support-master File: PopupMenuTest.java View source code |
/**
* Returns the location of our popup menu in its window.
*/
private int[] getPopupLocationInWindow() {
final int[] location = new int[2];
onView(withClassName(Matchers.is(DROP_DOWN_CLASS_NAME))).inRoot(isPlatformPopup()).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}
@Override
public String getDescription() {
return "Popup matcher";
}
@Override
public void perform(UiController uiController, View view) {
view.getLocationInWindow(location);
}
});
return location;
}
Example 15
Project: samlib-Info-master File: MyViewAction.java View source code |
static ViewAction clickChildViewWithId(final int id) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return null;
}
@Override
public String getDescription() {
return "Click on a child view with specified id.";
}
@Override
public void perform(UiController uiController, View view) {
View v = view.findViewById(id);
if (v != null) {
Log.i("TEST", "perform click");
v.performClick();
} else {
Log.e("TEST", "view not found");
}
}
};
}
Example 16
Project: apg-master File: CustomActions.java View source code |
public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception {
CanonicalizedPublicKeyRing ring = new ProviderHelper(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
final Object item = new KeyAdapter.KeyItem(ring);
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(TokenCompleteTextView.class);
}
@Override
public String getDescription() {
return "add completion token";
}
@Override
public void perform(UiController uiController, View view) {
((TokenCompleteTextView) view).addObject(item);
}
};
}
Example 17
Project: News-Android-App-master File: OrientationChangeAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
final Activity activity = (Activity) view.getContext();
activity.setRequestedOrientation(orientation);
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
throw new RuntimeException("Could not change orientation");
}
}
Example 18
Project: Rutgers-Course-Tracker-master File: OrientationChangeAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
final Activity activity = (Activity) view.getContext();
activity.setRequestedOrientation(orientation);
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
throw new RuntimeException("Could not change orientation");
}
}
Example 19
Project: android-calculatorpp-master File: OrientationChangeAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
requestOrientation(view);
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
throw new RuntimeException("Could not change orientation");
}
}
Example 20
Project: AppIntro-master File: OrientationChangeAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
final Activity activity = (Activity) view.getContext();
activity.setRequestedOrientation(orientation);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
throw new RuntimeException("Could not change orientation");
}
}
Example 21
Project: Catroid-master File: CustomActions.java View source code |
public static ViewAction wait(final int milliSeconds) {
return new ViewAction() {
@Override
public String getDescription() {
return "Wait for X milliseconds";
}
@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
uiController.loopMainThreadForAtLeast(milliSeconds);
}
};
}
Example 22
Project: countries-master File: EspressoUtils.java View source code |
public static ViewAction clickChildViewWithId(final int id) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isDisplayingAtLeast(90);
}
@Override
public String getDescription() {
return "Click on a child view with id " + id + ".";
}
@Override
public void perform(UiController uiController, View view) {
View v = view.findViewById(id);
if (v != null) {
v.performClick();
}
}
};
}
Example 23
Project: frisbee-master File: OrientationChangeAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
activity.setRequestedOrientation(orientation);
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
throw new RuntimeException("Could not change orientation");
}
}
Example 24
Project: Ironhide-master File: Zoom.java View source code |
private static Zoomer.Status sendLinearZoom(UiController uiController, float[][] startCoordinates, float[][] endCoordinates, float[] precision, int duration) {
checkNotNull(uiController);
checkNotNull(startCoordinates);
checkNotNull(endCoordinates);
checkNotNull(precision);
ZoomMotionEvents manager = new ZoomMotionEvents(uiController, precision);
boolean injectSuccess = manager.sendDownPair(startCoordinates);
for (int i = 0; i < ZOOM_EVENT_COUNT; i++) {
float alpha = (float) i / ZOOM_EVENT_COUNT;
if (!manager.sendMovementPair(linearInterpolation(alpha, startCoordinates, endCoordinates))) {
Log.e(TAG, "Injection of move event as part of the zoom failed. Sending cancel event.");
manager.sendCancelPair(linearInterpolation(alpha, startCoordinates, endCoordinates));
return FAILURE;
}
long loopDuration = manager.downTime + (long) (alpha * duration) - SystemClock.uptimeMillis();
if (loopDuration > ZoomMotionEvents.MIN_LOOP_TIME)
uiController.loopMainThreadForAtLeast(loopDuration);
}
injectSuccess = injectSuccess && manager.sendUpPair(endCoordinates);
if (injectSuccess)
return SUCCESS;
else {
Log.e(TAG, "Injection of up event as part of the zoom failed. Sending cancel event.");
manager.sendCancelPair(endCoordinates);
return FAILURE;
}
}
Example 25
Project: Material-BottomNavigation-master File: CustomSwipe.java View source code |
private static Swiper.Status sendLinearSwipe(UiController uiController, float[] startCoordinates, float[] endCoordinates, float[] precision, int duration) {
Preconditions.checkNotNull(uiController);
Preconditions.checkNotNull(startCoordinates);
Preconditions.checkNotNull(endCoordinates);
Preconditions.checkNotNull(precision);
float[][] steps = interpolate(startCoordinates, endCoordinates, SWIPE_EVENT_COUNT);
final int delayBetweenMovements = duration / steps.length;
MotionEvent downEvent = MotionEvents.sendDown(uiController, startCoordinates, precision).down;
try {
for (int i = 0; i < steps.length; i++) {
if (!MotionEvents.sendMovement(uiController, downEvent, steps[i])) {
Log.e(TAG, "Injection of move event as part of the swipe failed. Sending cancel event.");
MotionEvents.sendCancel(uiController, downEvent);
return Swiper.Status.FAILURE;
}
long desiredTime = downEvent.getDownTime() + delayBetweenMovements * i;
long timeUntilDesired = desiredTime - SystemClock.uptimeMillis();
if (timeUntilDesired > 10) {
uiController.loopMainThreadForAtLeast(timeUntilDesired);
}
}
if (!MotionEvents.sendUp(uiController, downEvent, endCoordinates)) {
Log.e(TAG, "Injection of up event as part of the swipe failed. Sending cancel event.");
MotionEvents.sendCancel(uiController, downEvent);
return Swiper.Status.FAILURE;
}
} finally {
downEvent.recycle();
}
return Swiper.Status.SUCCESS;
}
Example 26
Project: openintents-master File: TestSaveAsActivity.java View source code |
private boolean sendKeyEvent(UiController controller) throws InjectEventSecurityException {
boolean injected = false;
long eventTime = SystemClock.uptimeMillis();
for (int attempts = 0; !injected && attempts < 4; attempts++) {
injected = controller.injectKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER, 0, 0));
}
return injected;
}
Example 27
Project: PrettyBundle-master File: ExtViewActions.java View source code |
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
} while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
}
Example 28
Project: Scoops-master File: TestUtils.java View source code |
public void perform(UiController uiController, View view) {
RecyclerView recyclerView = (RecyclerView) view;
(new ScrollToPositionViewAction(this.position)).perform(uiController, view);
uiController.loopMainThreadUntilIdle();
View targetView = recyclerView.getChildAt(this.position).findViewById(this.viewId);
if (targetView == null) {
throw (new PerformException.Builder()).withActionDescription(this.toString()).withViewDescription(HumanReadables.describe(view)).withCause(new IllegalStateException("No view with id " + this.viewId + " found at position: " + this.position)).build();
} else {
this.viewAction.perform(uiController, targetView);
}
}
Example 29
Project: SwissManager-master File: RecyclerViewMatcherBase.java View source code |
public void perform(UiController uiController, View view) {
RecyclerView recyclerView = (RecyclerView) view;
(new ScrollToPositionViewAction(this.position)).perform(uiController, view);
uiController.loopMainThreadUntilIdle();
View targetView = recyclerView.getChildAt(this.position).findViewById(this.viewId);
if (targetView == null) {
throw (new PerformException.Builder()).withActionDescription(this.toString()).withViewDescription(HumanReadables.describe(view)).withCause(new IllegalStateException("No view with id " + this.viewId + " found at position: " + this.position)).build();
} else {
this.viewAction.perform(uiController, targetView);
}
}
Example 30
Project: u2020-mvp-master File: ViewActions.java View source code |
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
} while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
}
Example 31
Project: uhabits-master File: HabitViewActions.java View source code |
@Override
public void perform(UiController uiController, View view) {
if (view.getId() != R.id.checkmarkPanel)
throw new InvalidParameterException("View must have id llButtons");
LinearLayout llButtons = (LinearLayout) view;
int count = llButtons.getChildCount();
for (int i = 0; i < count; i++) {
TextView tvButton = (TextView) llButtons.getChildAt(i);
clickAction.perform(uiController, tvButton);
}
}
Example 32
Project: wheelmap-android-master File: ScreengrabTest.java View source code |
public static ViewAction waitFor(final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "Wait for " + millis + " milliseconds.";
}
@Override
public void perform(UiController uiController, final View view) {
uiController.loopMainThreadForAtLeast(millis);
}
};
}
Example 33
Project: android-PictureInPicture-master File: MainActivityTest.java View source code |
private static ViewAction showControls() {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(MovieView.class);
}
@Override
public String getDescription() {
return "Show controls of MovieView";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
((MovieView) view).showControls();
uiController.loopMainThreadUntilIdle();
}
};
}
Example 34
Project: BottomNavigation-master File: Utils.java View source code |
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
} while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
}
Example 35
Project: connectbot-master File: StartupTest.java View source code |
/*
* This is to work around a race condition where the software keyboard does not dismiss in time
* and you get a Security Exception.
*
* From: https://code.google.com/p/android-test-kit/issues/detail?id=79#c7
*/
public static ViewAction closeSoftKeyboard() {
return new ViewAction() {
/**
* The real {@link CloseKeyboardAction} instance.
*/
private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction();
@Override
public Matcher<View> getConstraints() {
return mCloseSoftKeyboard.getConstraints();
}
@Override
public String getDescription() {
return mCloseSoftKeyboard.getDescription();
}
@Override
public void perform(final UiController uiController, final View view) {
mCloseSoftKeyboard.perform(uiController, view);
uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS);
}
};
}
Example 36
Project: yandex-money-sdk-android-master File: MoreViewActions.java View source code |
@Override
public final void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
long finishTime = System.currentTimeMillis() + duration;
while (System.currentTimeMillis() < finishTime) {
if (isConditionMet(view)) {
return;
}
uiController.loopMainThreadForAtLeast(50L);
}
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
}
Example 37
Project: android-topeka-master File: SolveQuizUtil.java View source code |
private static void setAlphaPickerProgress(final AlphaPickerQuiz quiz) {
onView(allOf(isDescendantOfA(hasSibling(withText(quiz.getQuestion()))), withId(R.id.seekbar))).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(SeekBar.class);
}
@Override
public String getDescription() {
return "Set progress on AlphaPickerQuizView";
}
@Override
public void perform(UiController uiController, View view) {
List<String> alphabet = Arrays.asList(InstrumentationRegistry.getTargetContext().getResources().getStringArray(R.array.alphabet));
SeekBar seekBar = (SeekBar) view;
seekBar.setProgress(alphabet.indexOf(quiz.getAnswer()));
}
});
}
Example 38
Project: canarinho-master File: DemoWatchersInstrumentationTest.java View source code |
private ViewAction paste(final String type) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
// noinspection unchecked
Matcher<View> matchers = allOf(isDisplayed());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
return allOf(matchers, supportsInputMethods());
} else {
// view for input).
return allOf(matchers, anyOf(supportsInputMethods(), isAssignableFrom(SearchView.class)));
}
}
@Override
public String getDescription() {
return "Straight typing into view";
}
@Override
public void perform(UiController uiController, View view) {
((EditText) view).setText(type);
}
};
}
Example 39
Project: ChipsLayoutManager-master File: RecyclerViewEspressoFactory.java View source code |
@Override
public void performAction(UiController uiController, RecyclerView recyclerView) {
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
SmoothScrollToPositionRecyclerViewAction.this.onScrollStateChanged(recyclerView, newState);
}
});
recyclerView.smoothScrollToPosition(position);
}
Example 40
Project: glucosio-android-master File: CustomClickAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
float[] coordinates = coordinatesProvider.calculateCoordinates(view);
float[] precision = precisionDescriber.describePrecision();
Tapper.Status status = Tapper.Status.FAILURE;
int loopCount = 0;
// 'RollBack' ViewAction which when executed will undo the effects of long press.
while (status != Tapper.Status.SUCCESS && loopCount < 3) {
try {
status = tapper.sendTap(uiController, coordinates, precision);
} catch (RuntimeException re) {
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(re).build();
}
int duration = ViewConfiguration.getPressedStateDuration();
// ensures that all work enqueued to process the tap has been run.
if (duration > 0) {
uiController.loopMainThreadForAtLeast(duration);
}
if (status == Tapper.Status.WARNING) {
if (rollbackAction.isPresent()) {
rollbackAction.get().perform(uiController, view);
} else {
break;
}
}
loopCount++;
}
if (status == Tapper.Status.FAILURE) {
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new RuntimeException(String.format("Couldn't " + "click at: %s,%s precision: %s, %s . Tapper: %s coordinate provider: %s precision " + "describer: %s. Tried %s times. With Rollback? %s", coordinates[0], coordinates[1], precision[0], precision[1], tapper, coordinatesProvider, precisionDescriber, loopCount, rollbackAction.isPresent()))).build();
}
if (tapper == Tap.SINGLE && view instanceof WebView) {
// WebViews will not process click events until double tap
// timeout. Not the best place for this - but good for now.
uiController.loopMainThreadForAtLeast(ViewConfiguration.getDoubleTapTimeout());
}
}
Example 41
Project: IBM-Ready-App-for-Telecommunications-master File: TextPageTest.java View source code |
/**
* Gets the text from a TextView
* @param matcher The matched view to extract text from
* @return The string in the view
*/
String getText(final Matcher<View> matcher) {
final String[] stringHolder = { null };
onView(matcher).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(TextView.class);
}
@Override
public String getDescription() {
return "getting text from a TextView";
}
@Override
public void perform(UiController uiController, View view) {
//Save, because of check in getConstraints()
TextView tv = (TextView) view;
stringHolder[0] = tv.getText().toString();
}
});
return stringHolder[0];
}
Example 42
Project: orgzly-android-master File: EspressoUtils.java View source code |
/**
* Give keyboard time to close, to avoid java.lang.SecurityException
* if hidden button is clicked next.
*/
static ViewAction closeSoftKeyboardWithDelay() {
return new ViewAction() {
/**
* The delay time to allow the soft keyboard to dismiss.
*/
private static final long KEYBOARD_DISMISSAL_DELAY_MILLIS = 1000L;
/**
* The real {@link CloseKeyboardAction} instance.
*/
private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction();
@Override
public Matcher<View> getConstraints() {
return mCloseSoftKeyboard.getConstraints();
}
@Override
public String getDescription() {
return mCloseSoftKeyboard.getDescription();
}
@Override
public void perform(final UiController uiController, final View view) {
mCloseSoftKeyboard.perform(uiController, view);
uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS);
}
};
}
Example 43
Project: shoppinglist-master File: ShoppingActivityTest.java View source code |
/**
* Perform action of waiting.
*/
public static ViewAction waitFor(final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadForAtLeast(millis);
uiController.loopMainThreadUntilIdle();
}
};
}
Example 44
Project: wire-android-master File: CustomGeneralClickAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
float[] coordinates = coordinatesProvider.calculateCoordinates(view);
float[] precision = precisionDescriber.describePrecision();
Tapper.Status status = Tapper.Status.FAILURE;
int loopCount = 0;
while (status != Tapper.Status.SUCCESS && loopCount < 3) {
try {
status = tapper.sendTap(uiController, coordinates, precision);
} catch (RuntimeException re) {
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(re).build();
}
int duration = ViewConfiguration.getPressedStateDuration();
// ensures that all work enqueued to process the tap has been run.
if (duration > 0) {
uiController.loopMainThreadForAtLeast(duration);
}
if (status == Tapper.Status.WARNING) {
break;
}
loopCount++;
}
if (status == Tapper.Status.FAILURE) {
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new RuntimeException(String.format("Couldn't " + "click at: %s,%s precision: %s, %s . Tapper: %s coordinate provider: %s precision " + "describer: %s. Tried %s times. With Rollback? %s", coordinates[0], coordinates[1], precision[0], precision[1], tapper, coordinatesProvider, precisionDescriber, loopCount, false))).build();
}
if (tapper == Tap.SINGLE && view instanceof WebView) {
// WebViews will not process click events until double tap
// timeout. Not the best place for this - but good for now.
uiController.loopMainThreadForAtLeast(ViewConfiguration.getDoubleTapTimeout());
}
}
Example 45
Project: Equate-master File: EspressoTestUtils.java View source code |
/**
* Clicks on the tab for the provided Unit Type name. Note that the Unit Type
* doesn't need to be visible.
*/
public static void selectUnitTypeDirect(final String unitTypeName) {
onView(allOf(withText(unitTypeName))).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
// no constraints, they are checked above
return isEnabled();
}
@Override
public String getDescription() {
return "click unit type" + unitTypeName;
}
@Override
public void perform(UiController uiController, View view) {
view.performClick();
}
});
}
Example 46
Project: iosched-master File: MatchersHelper.java View source code |
/**
* This returns the text for the view that has been matched with {@code matcher}. The matched
* view is expected to be a {@link TextView}. This is different from matching a view by text,
* this is intended to be used when matching a view by another mean (for example, by id) but
* when we need to know the text of that view, for use later in a test.
* <p/>
* In general, this isn't good practice as tests should be written using mock data (so we always
* know what the data is) but this enables us to write tests that are written using real data
* (so we don't always know what the data is but we want to verify something later in a test).
* This is enables us to write UI tests before refactoring a feature to make it easier to mock
* the data.
*/
public static String getText(final Matcher<View> matcher) {
/**
* We cannot use a String directly as we need to make it final to access it inside the
* inner method but we cannot reassign a value to a final String.
*/
final String[] stringHolder = { null };
onView(matcher).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(TextView.class);
}
@Override
public String getDescription() {
return "getting text from a TextView";
}
@Override
public void perform(UiController uiController, View view) {
TextView tv = (TextView) view;
stringHolder[0] = tv.getText().toString();
}
});
return stringHolder[0];
}
Example 47
Project: Kore-master File: EspressoTestUtils.java View source code |
/**
* Returns the current active activity. Use this when the originally started activity
* started a new activity and you need the reference to the new activity.
* @return reference to the current active activity
*/
public static Activity getActivity() {
final Activity[] activity = new Activity[1];
onView(allOf(withId(android.R.id.content), isDisplayed())).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(View.class);
}
@Override
public String getDescription() {
return "getting current activity";
}
@Override
public void perform(UiController uiController, View view) {
if (view.getContext() instanceof Activity) {
activity[0] = ((Activity) view.getContext());
}
}
});
return activity[0];
}
Example 48
Project: easy-adapter-master File: CustomViewActions.java View source code |
@Override
public void perform(UiController uiController, View view) {
View viewToClick = view.findViewById(mChildViewId);
mGeneralClickAction.perform(uiController, viewToClick != null ? viewToClick : view);
}
Example 49
Project: spotify-tv-master File: SpoonScreenshotAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
Spoon.screenshot(getActivity(view), tag, testClass, testMethod);
}
Example 50
Project: CleanGUITestArchitecture-master File: SpoonScreenshotAction.java View source code |
@Override
public void perform(final UiController uiController, final View view) {
lastScreenshot = Spoon.screenshot(getActivity(view), mTag, mTestClass, mTestMethod);
}
Example 51
Project: PhilHackerNews-master File: OrientationChangeAction.java View source code |
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
final Activity activity = (Activity) view.getContext();
activity.setRequestedOrientation(orientation);
}
Example 52
Project: espresso-cucumber-master File: SpoonScreenshotAction.java View source code |
@Override
public void perform(final UiController uiController, final View view) {
sLastScreenshot = Spoon.screenshot(getActivity(view), mTag, mTestClass, mTestMethod);
}