android.support.test.espresso.ViewAction Java Examples
The following examples show how to use
android.support.test.espresso.ViewAction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItClickerActivity.java From SmoothClicker with MIT License | 6 votes |
/** * 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 #2
Source File: MainActivityTest.java From android-PictureInPicture with Apache License 2.0 | 6 votes |
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 #3
Source File: ViewActions.java From u2020-mvp with Apache License 2.0 | 6 votes |
/** * Perform action of waiting for a specific time. Useful when you need * to wait for animations to end and Espresso fails at waiting. * <p/> * E.g.: * onView(isRoot()).perform(waitAtLeast(Sampling.SECONDS_15)); * * @param millis * @return */ public static ViewAction waitAtLeast(final long millis) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return anything(); } @Override public String getDescription() { return "wait for at least " + millis + " millis."; } @Override public void perform(final UiController uiController, final View view) { uiController.loopMainThreadUntilIdle(); uiController.loopMainThreadForAtLeast(millis); } }; }
Example #4
Source File: MediaSessionPlaybackActivityTest.java From android-PictureInPicture with Apache License 2.0 | 6 votes |
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 #5
Source File: TestMainActivity.java From polling-station-app with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test if the manual input activity opens. */ @Test public void testGoToManual() { onView(withId(R.id.manual_input_button)).check(matches(allOf( isEnabled(), isClickable()))).perform( new ViewAction() { @Override public Matcher<View> getConstraints() { return isEnabled(); // no constraints, they are checked above } @Override public String getDescription() { return "click manual input button"; } @Override public void perform(UiController uiController, View view) { view.performClick(); } } ); intended(hasComponent(ManualInputActivity.class.getName())); }
Example #6
Source File: InputConnectionTest.java From TokenAutoComplete with Apache License 2.0 | 6 votes |
public static ViewAction forceCommitText(final String text) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(ContactsCompletionView.class); } @Override public String getDescription() { return null; } @Override public void perform(UiController uiController, View view) { ContactsCompletionView completionView = (ContactsCompletionView)view; InputConnection connection = completionView.testAccessibleInputConnection; connection.commitText(text, 1); } }; }
Example #7
Source File: MapActivityTest.java From mobile-android-samples with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #8
Source File: AnecdoteRecyclerViewAction.java From Anecdote with Apache License 2.0 | 6 votes |
public 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) { v.performClick(); } } }; }
Example #9
Source File: AnecdoteRecyclerViewAction.java From Anecdote with Apache License 2.0 | 6 votes |
public static ViewAction clickAnecdoteTextViewWithId(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) { v.performClick(); } } }; }
Example #10
Source File: ColumnTest.java From ChipsLayoutManager with Apache License 2.0 | 6 votes |
@Test public synchronized void smoothScrollToPosition_ScrollItemIsNotVisible_FirstVisiblePositionsEqualsScrollingTarget() throws Exception { //arrange InstrumentalUtil.waitForIdle(); //act ViewAction scrollAction = smoothScrollToPosition(18); //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (scrollAction) { recyclerView.perform(scrollAction); //wait for completion of SmoothScrollAction scrollAction.wait(); } //assert int actual = layoutManager.findFirstCompletelyVisibleItemPosition(); assertEquals(18, actual); }
Example #11
Source File: RowTest.java From ChipsLayoutManager with Apache License 2.0 | 6 votes |
@Test public synchronized void smoothScrollToPosition_LMInInitialState_FirstVisiblePositionsEqualsScrollingTarget() throws Exception { //arrange InstrumentalUtil.waitForIdle(); //act ViewAction scrollAction = smoothScrollToPosition(8); //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (scrollAction) { recyclerView.perform(scrollAction); //wait for completion of SmoothScrollAction scrollAction.wait(); } //assert int actual = layoutManager.findFirstCompletelyVisibleItemPosition(); assertEquals(8, actual); }
Example #12
Source File: AppBarLayoutAction.java From espresso-macchiato with MIT License | 6 votes |
public static ViewAction collapse() { return new ViewAction() { @Override public Matcher<View> getConstraints() { return ViewMatchers.isAssignableFrom(AppBarLayout.class); } @Override public String getDescription() { return "Collapse AppBarLayout inside of a CollapsingToolbarLayout."; } @Override public void perform(UiController uiController, View view) { AppBarLayout appBarLayout = (AppBarLayout) view; appBarLayout.setExpanded(false, false); } }; }
Example #13
Source File: AppBarLayoutAction.java From espresso-macchiato with MIT License | 6 votes |
public static ViewAction expand() { return new ViewAction() { @Override public Matcher<View> getConstraints() { return ViewMatchers.isAssignableFrom(AppBarLayout.class); } @Override public String getDescription() { return "Expand AppBarLayout inside of a CollapsingToolbarLayout."; } @Override public void perform(UiController uiController, View view) { AppBarLayout appBarLayout = (AppBarLayout) view; appBarLayout.setExpanded(true, false); } }; }
Example #14
Source File: EspWait.java From espresso-macchiato with MIT License | 6 votes |
public static void forIdle() { onView(isRoot()).perform(new ViewAction() { @Override public Matcher<View> getConstraints() { return isRoot(); } @Override public String getDescription() { return null; } @Override public void perform(UiController uiController, View view) { uiController.loopMainThreadForAtLeast(1000); uiController.loopMainThreadUntilIdle(); } }); }
Example #15
Source File: ItSelectMultiPointsActivity.java From SmoothClicker with MIT License | 6 votes |
/** * 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 #16
Source File: ColumnTest.java From ChipsLayoutManager with Apache License 2.0 | 6 votes |
@Test public synchronized void smoothScrollToPosition_ScrollItemIsVisible_ScrollItemDockedToStartBorder() throws Exception { //arrange InstrumentalUtil.waitForIdle(); //act ViewAction scrollAction = smoothScrollToPosition(3); //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (scrollAction) { recyclerView.perform(scrollAction); //wait for completion of SmoothScrollAction scrollAction.wait(); } //assert int actual = layoutManager.findFirstCompletelyVisibleItemPosition(); assertEquals(3, actual); }
Example #17
Source File: StepperNavigationActions.java From android-material-stepper with Apache License 2.0 | 6 votes |
/** * Clicks the Next button. */ public static ViewAction clickNext() { return new AbstractStepperNavigationAction() { @Override public String getDescription() { return "Click on the Next button"; } @Override protected void performAction(StepperLayout stepperLayout) { View nextButton = stepperLayout.findViewById(com.stepstone.stepper.R.id.ms_stepNextButton); nextButton.performClick(); } }; }
Example #18
Source File: StepperNavigationActions.java From android-material-stepper with Apache License 2.0 | 6 votes |
/** * Clicks the Back button. */ public static ViewAction clickBack() { return new AbstractStepperNavigationAction() { @Override public String getDescription() { return "Click on the Back button"; } @Override protected void performAction(StepperLayout stepperLayout) { View backButton = stepperLayout.findViewById(com.stepstone.stepper.R.id.ms_stepPrevButton); backButton.performClick(); } }; }
Example #19
Source File: StepperNavigationActions.java From android-material-stepper with Apache License 2.0 | 6 votes |
/** * Clicks the Complete button. */ public static ViewAction clickComplete() { return new AbstractStepperNavigationAction() { @Override public String getDescription() { return "Click on the Complete button"; } @Override protected void performAction(StepperLayout stepperLayout) { View completeButton = stepperLayout.findViewById(com.stepstone.stepper.R.id.ms_stepCompleteButton); completeButton.performClick(); } }; }
Example #20
Source File: Step4CalculatorActivityTest.java From android-agera with Apache License 2.0 | 6 votes |
public static ViewAction setProgress(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 #21
Source File: Step4CalculatorActivityFinalTest.java From android-agera with Apache License 2.0 | 6 votes |
public static ViewAction setProgress(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 #22
Source File: CameraViewActions.java From cameraview with Apache License 2.0 | 6 votes |
static ViewAction setAspectRatio(@NonNull final AspectRatio ratio) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(CameraView.class); } @Override public String getDescription() { return "Set aspect ratio to " + ratio; } @Override public void perform(UiController controller, View view) { ((CameraView) view).setAspectRatio(ratio); } }; }
Example #23
Source File: StepListFragmentTest.java From friendly-plans with GNU General Public License v3.0 | 6 votes |
public static ViewAction clickChildViewWithId(final int id) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return null; } @Override public String getDescription() { return null; } @Override public void perform(UiController uiController, View view) { View v = view.findViewById(id); v.performClick(); } }; }
Example #24
Source File: EspressoTestUtils.java From Equate with GNU General Public License v3.0 | 6 votes |
/** * 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() { return isEnabled(); // no constraints, they are checked above } @Override public String getDescription() { return "click unit type" + unitTypeName; } @Override public void perform(UiController uiController, View view) { view.performClick(); } } ); }
Example #25
Source File: ViewActions.java From u2020-mvp with Apache License 2.0 | 6 votes |
/** * Perform action of waiting until UI thread is free. * <p/> * E.g.: * onView(isRoot()).perform(waitUntilIdle()); * * @return */ public static ViewAction waitUntilIdle() { return new ViewAction() { @Override public Matcher<View> getConstraints() { return anything(); } @Override public String getDescription() { return "wait until UI thread is free"; } @Override public void perform(final UiController uiController, final View view) { uiController.loopMainThreadUntilIdle(); } }; }
Example #26
Source File: ExtViewActions.java From PrettyBundle with Apache License 2.0 | 6 votes |
/** * Perform action of waiting for a specific time. Useful when you need * to wait for animations to end and Espresso fails at waiting. * <p/> * E.g.: * onView(isRoot()).perform(waitAtLeast(Sampling.SECONDS_15)); * * @param millis * @return */ public static ViewAction waitAtLeast(final long millis) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return anything(); } @Override public String getDescription() { return "wait for at least " + millis + " millis."; } @Override public void perform(final UiController uiController, final View view) { uiController.loopMainThreadUntilIdle(); uiController.loopMainThreadForAtLeast(millis); } }; }
Example #27
Source File: InputConnectionTest.java From TokenAutoComplete with Apache License 2.0 | 6 votes |
public static ViewAction forceComposingText(final String text) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(ContactsCompletionView.class); } @Override public String getDescription() { return null; } @Override public void perform(UiController uiController, View view) { ContactsCompletionView completionView = (ContactsCompletionView)view; InputConnection connection = completionView.testAccessibleInputConnection; connection.setComposingText(text, -1); } }; }
Example #28
Source File: ComprehensionTest.java From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private 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) { TextView tv = (TextView) view; stringHolder[0] = tv.getText().toString(); } }); return stringHolder[0]; }
Example #29
Source File: ApplicationTest.java From CompactCalendarView with MIT License | 6 votes |
public ViewAction clickXY(final float x, final float y){ final DisplayMetrics dm = activityRule.getActivity().getResources().getDisplayMetrics() ; final float spX = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, x, dm); final float spY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, y, dm); 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] + spX; final float screenY = screenPos[1] + spY; float[] coordinates = {screenX, screenY}; return coordinates; } }, Press.FINGER); }
Example #30
Source File: CustomViewActions.java From android-test-demo with MIT License | 6 votes |
public static ViewAction clickEventItemAvatar() { return new ViewAction() { @Override public Matcher<View> getConstraints() { return null; } @Override public String getDescription() { return null; } @Override public void perform(UiController uiController, View view) { view.findViewById(R.id.event_list_item_avatar).callOnClick(); } }; }