Java Code Examples for android.support.test.espresso.action.Press

The following are top voted examples for showing how to use android.support.test.espresso.action.Press. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: espresso-commons   File: RecyclerViewUtils.java   View source code 6 votes vote down vote up
/**
 * Returns an action that clicks a descendant of the view matched with the given resource id.
 *
 * @param id resource id of the view to click.
 * @return an action that clicks a descendant of the view matched with the given resource id.
 */
public static ViewAction clickDescendantViewWithId(@IdRes final int id) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return hasDescendant(withId(id));
        }

        @Override
        public String getDescription() {
            return "Click on a descendant view with id: " + id;
        }

        @Override
        public void perform(UiController uiController, View view) {
            GeneralClickAction action = new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER);
            View target = view.findViewById(id);
            // getConstraints() guarantees that the target never be null.
            action.perform(uiController, target);
        }
    };
}
 
Example 2
Project: orgzly-android   File: NewNoteTest.java   View source code 6 votes vote down vote up
@Test
public void testNewNoteFromQuickMenuWhenCabIsDisplayed() {
    shelfTestUtils.setupBook("booky", "Booky Preface\n* 1\n** 2\n*** 3\n*** 4\n** 5\n* 6");
    activityRule.launchActivity(null);
    onView(allOf(withText("booky"), isDisplayed())).perform(click());

    onView(withId(R.id.action_context_bar)).check(matches(not(isDisplayed())));
    onListItem(2).perform(longClick());
    /* Swipe left. */
    onListItem(2).perform(new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER, GeneralLocation.CENTER_LEFT, Press.FINGER));
    onView(withId(R.id.action_context_bar)).check(matches(isDisplayed()));
    onListItem(2).onChildView(withId(R.id.item_menu_new_under_btn)).perform(click());
    onView(withId(R.id.fragment_note_title)).check(matches(isDisplayed()));
    onView(withId(R.id.done)).check(matches(isDisplayed()));
    onView(withId(R.id.action_context_bar)).check(matches(not(isDisplayed())));
}
 
Example 3
Project: espresso-sample-for-droidkaigi2017   File: RecyclerViewUtils.java   View source code 6 votes vote down vote up
/**
 * Returns an action that clicks a descendant of the view matched with the given resource id.
 */
public static ViewAction clickDescendantViewWithId(@IdRes final int id) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return hasDescendant(withId(id));
        }

        @Override
        public String getDescription() {
            return "Click on a descendant view with id: " + id;
        }

        @Override
        public void perform(UiController uiController, View view) {
            GeneralClickAction action = new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER);
            View target = view.findViewById(id);
            // getConstraints() guarantees that the target never be null.
            action.perform(uiController, target);
        }
    };
}
 
Example 4
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 6 votes vote down vote up
@Test
@MediumTest
public void testSwipeUpToExpand() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 5
Project: SmoothClicker   File: ItSelectMultiPointsActivity.java   View source code 6 votes vote down vote up
/**
 * Custom ViewAction to click on dedicated coordinates
 * @param x -
 * @param y -
 * @return ViewAction -
 */
private ViewAction clickXY( final int x, final int y ){
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates( View view ){

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;

                    return new float[]{screenX, screenY};

                }
            },
            Press.FINGER);
}
 
Example 6
Project: Todo.txt-gDrive   File: MainActivityTest.java   View source code 6 votes vote down vote up
private static ViewAction clickXY(final int x, final int y) {
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates(View view) {

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;
                    float[] coordinates = {screenX, screenY};

                    return coordinates;
                }
            },
            Press.FINGER);
}
 
Example 7
Project: translationRecorder   File: TestUtils.java   View source code 6 votes vote down vote up
public static ViewAction clickXY(final int x, final int y){
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates(View view) {

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;
                    float[] coordinates = {screenX, screenY};

                    return coordinates;
                }
            },
            Press.FINGER);
}
 
Example 8
Project: akvo-caddisfly   File: TestUtil.java   View source code 6 votes vote down vote up
public static ViewAction clickPercent(final float pctX, final float pctY) {
    return new GeneralClickAction(
            Tap.SINGLE,
            view -> {

                final int[] screenPos = new int[2];
                view.getLocationOnScreen(screenPos);
                int w = view.getWidth();
                int h = view.getHeight();

                float x = w * pctX;
                float y = h * pctY;

                final float screenX = screenPos[0] + x;
                final float screenY = screenPos[1] + y;

                return new float[]{screenX, screenY};
            },
            Press.FINGER);
}
 
Example 9
Project: SwipeCoordinator   File: ViewActions.java   View source code 5 votes vote down vote up
static ViewAction swipeRightNotReachingThreshold(Context context) {
  final float x = getWidthScreen(context) * 0.3f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {x, 0f};
    }
  }, Press.FINGER);
}
 
Example 10
Project: SwipeCoordinator   File: ViewActions.java   View source code 5 votes vote down vote up
static ViewAction swipeRightReachingThreshold(Context context) {
  final float x = getWidthScreen(context) * 0.8f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {x, 0f};
    }
  }, Press.FINGER);
}
 
Example 11
Project: SwipeCoordinator   File: ViewActions.java   View source code 5 votes vote down vote up
static ViewAction swipeDownNotReachingThreshold(Context context) {
  final float y = getHeightScreen(context) * 0.3f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {0f, y};
    }
  }, Press.FINGER);
}
 
Example 12
Project: SwipeCoordinator   File: ViewActions.java   View source code 5 votes vote down vote up
static ViewAction swipeDownReachingThreshold(Context context) {
  final float y = getHeightScreen(context) * 0.8f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {0f, y};
    }
  }, Press.FINGER);
}
 
Example 13
Project: Material-BottomNavigation   File: ViewActionsCompat.java   View source code 5 votes vote down vote up
public static ViewAction swipeUp(final Swiper swipe) {
    return ViewActions.actionWithAssertions(new GeneralSwipeAction(
        swipe,
        GeneralLocation.CENTER,
        GeneralLocation.TOP_CENTER,
        Press.FINGER
    ));
}
 
Example 14
Project: Material-BottomNavigation   File: ViewActionsCompat.java   View source code 5 votes vote down vote up
public static ViewAction swipeDown(final Swiper swipe) {
    return ViewActions.actionWithAssertions(new GeneralSwipeAction(
        swipe,
        GeneralLocation.CENTER,
        GeneralLocation.BOTTOM_CENTER,
        Press.FINGER
    ));
}
 
Example 15
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testHalfExpandedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_HALF_EXPANDED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 16
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testCollapsedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 17
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testInvisible() throws Throwable {
  // Make the bottomsheet invisible
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          getBottomSheet().setVisibility(View.INVISIBLE);
          assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
      });
  // Swipe up as if to expand it
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              not(ViewMatchers.isDisplayed())));
  // Check that the bottom sheet stays the same collapsed state
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
      });
}
 
Example 18
Project: SmoothClicker   File: ItClickerActivity.java   View source code 5 votes vote down vote up
/**
 * Custom ViewAction to click on dedicated coordinates
 * @param x -
 * @param y -
 * @return ViewAction -
 */
private ViewAction clickXY( final int x, final int y ){
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates( View view ){

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;

                    return new float[]{screenX, screenY};

                }
            },
            Press.FINGER);
}
 
Example 19
Project: material-activity-chooser   File: ViewActions.java   View source code 5 votes vote down vote up
public static ViewAction swipeBottomSheetDown() {
    /* The default swipe action has a constraint where the swiped view has to be displayed in at least 90%,
     * which is not the case with bottom sheets...
     */
    return new NoConstraintsSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER,
            GeneralLocation. BOTTOM_CENTER, Press.FINGER);
}
 
Example 20
Project: material-activity-chooser   File: ViewActions.java   View source code 5 votes vote down vote up
public static ViewAction swipeBottomSheetUp() {
    /* The default swipe action has a constraint where the swiped view has to be displayed in at least 90%,
     * which is not the case with bottom sheets...
     */
    return new NoConstraintsSwipeAction(Swipe.FAST, GeneralLocation.VISIBLE_CENTER,
            GeneralLocation. TOP_CENTER, Press.FINGER);
}
 
Example 21
Project: Bill-Calculator   File: Tester.java   View source code 5 votes vote down vote up
ViewAction swipeAwayRight() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.FAST,
            GeneralLocation.CENTER,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates(View view) {
                    float xy[] = GeneralLocation.CENTER_RIGHT.calculateCoordinates(view);
                    xy[0] += 20f * view.getWidth();
                    return xy;
                }
            },
            Press.FINGER));
}
 
Example 22
Project: ChimpCheck   File: ChimpActionFactory.java   View source code 4 votes vote down vote up
public static ViewAction clickXY(final int x, final int y){
    return new GeneralClickAction(
            Tap.SINGLE,
            getCoordinatesProvider(x, y),
            Press.FINGER);
}
 
Example 23
Project: ChimpCheck   File: ChimpActionFactory.java   View source code 4 votes vote down vote up
public static ViewAction longClickXY(final int x, final int y){
    return new GeneralClickAction(
            Tap.LONG,
            getCoordinatesProvider(x, y),
            Press.FINGER);
}
 
Example 24
Project: SwipeOpenItemTouchHelper   File: SwipeOpenItemTouchHelperTest.java   View source code 4 votes vote down vote up
/**
 * Uses a slow swipe to simulate a scroll
 * @return the view action
 */
private ViewAction scroll() {
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.BOTTOM_CENTER,
      GeneralLocation.TOP_CENTER, Press.FINGER);
}
 
Example 25
Project: SwipeOpenItemTouchHelper   File: SwipeOpenItemTouchHelperTest.java   View source code 4 votes vote down vote up
private static ViewAction swipeRight() {
  return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_LEFT,
      GeneralLocation.CENTER_RIGHT, Press.FINGER);
}
 
Example 26
Project: SwipeOpenItemTouchHelper   File: SwipeOpenItemTouchHelperTest.java   View source code 4 votes vote down vote up
private static ViewAction swipeLeft() {
  return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_RIGHT,
      GeneralLocation.CENTER_LEFT, Press.FINGER);
}
 
Example 27
Project: material-activity-chooser   File: ViewActions.java   View source code 4 votes vote down vote up
public static ViewAction clickOnTop() {
    return new GeneralClickAction(Tap.SINGLE, GeneralLocation.TOP_CENTER, Press.FINGER);
}
 
Example 28
Project: tagscout   File: TagsScreenTest.java   View source code 4 votes vote down vote up
public static ViewAction swipeDown() {
    return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_CENTER,
                                  GeneralLocation.BOTTOM_CENTER, Press.FINGER
    );
}
 
Example 29
Project: PrettyBundle   File: ExtViewActions.java   View source code 4 votes vote down vote up
public static ViewAction swipeTop() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
}
 
Example 30
Project: PrettyBundle   File: ExtViewActions.java   View source code 4 votes vote down vote up
public static ViewAction swipeBottom() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER);
}
 
Example 31
Project: agera   File: MainActivityTest.java   View source code 4 votes vote down vote up
private static ViewAction swipeDown() {
  return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER,
      GeneralLocation.BOTTOM_CENTER, Press.FINGER);
}
 
Example 32
Project: agera   File: MainActivityTest.java   View source code 4 votes vote down vote up
private static ViewAction swipeDown() {
  return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER,
      GeneralLocation.BOTTOM_CENTER, Press.FINGER);
}
 
Example 33
Project: RxBinding   File: RxViewPagerTest.java   View source code 4 votes vote down vote up
private static ViewAction swipeLeft() {
  return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_RIGHT,
      GeneralLocation.CENTER_LEFT, Press.FINGER);
}
 
Example 34
Project: RxBinding   File: RxSwipeRefreshLayoutTest.java   View source code 4 votes vote down vote up
private static ViewAction swipeDown() {
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_CENTER,
      GeneralLocation.BOTTOM_CENTER, Press.FINGER);
}
 
Example 35
Project: RxBinding   File: RxSwipeDismissBehaviorTest.java   View source code 4 votes vote down vote up
private static ViewAction swipeRight() {
  return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_LEFT,
      GeneralLocation.CENTER_RIGHT, Press.FINGER);
}
 
Example 36
Project: Bill-Calculator   File: CustomClickAction.java   View source code 4 votes vote down vote up
public CustomClickAction() {
    this(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER);
}
 
Example 37
Project: u2020-mvp   File: ViewActions.java   View source code 4 votes vote down vote up
public static ViewAction swipeTop() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
}
 
Example 38
Project: u2020-mvp   File: ViewActions.java   View source code 4 votes vote down vote up
public static ViewAction swipeBottom() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER);
}
 
Example 39
Project: easy-adapter   File: CustomViewActions.java   View source code 4 votes vote down vote up
public static ViewAction clickOnChild(int childViewId) {
    return actionWithAssertions((new ChildClickAction(
            new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER),
            childViewId)));
}
 
Example 40
Project: GitHub   File: Utils.java   View source code 2 votes vote down vote up
/**
 * Returns an action that performs a swipe right-to-left across the vertical center of the
 * view. The swipe doesn't start at the very edge of the view, but is a bit offset.<br>
 * <br>
 * View constraints:
 * <ul>
 * <li>must be displayed on screen
 * <ul>
 */
public static ViewAction swipeLeftSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.CENTER_RIGHT, -EDGE_FUZZ_FACTOR, 0),
            GeneralLocation.CENTER_LEFT, Press.FINGER));
}