android.support.test.espresso.UiController Java Examples
The following examples show how to use
android.support.test.espresso.UiController.
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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
Source File: CustomActions.java From Villains-and-Heroes with Apache License 2.0 | 6 votes |
public static ViewAction typeQuery(final String value) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return allOf(isDisplayed(), isAssignableFrom(SearchView.class)); } @Override public void perform(UiController uiController, View view) { ((SearchView) view).setQuery(value, false); } @Override public String getDescription() { return String.format("type query(%s)", value); } }; }
Example #9
Source File: ViewText.java From px-android with MIT License | 6 votes |
public static String getTextFromMatcher(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(final UiController uiController, final View view) { final TextView tv = (TextView) view; stringHolder[0] = tv.getText().toString(); } }); return stringHolder[0]; }
Example #10
Source File: TestUtils.java From Awesome-WanAndroid with Apache License 2.0 | 6 votes |
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: CameraViewTest.java From cameraview with Apache License 2.0 | 6 votes |
@Test public void testTakePicture() throws Exception { TakePictureIdlingResource resource = new TakePictureIdlingResource( (CameraView) rule.getActivity().findViewById(R.id.camera)); onView(withId(R.id.camera)) .perform(new AnythingAction("take picture") { @Override public void perform(UiController uiController, View view) { CameraView cameraView = (CameraView) view; cameraView.takePicture(); } }); try { IdlingRegistry.getInstance().register(resource); onView(withId(R.id.camera)) .perform(waitFor(1000)) .check(showingPreview()); assertThat("Didn't receive valid JPEG data.", resource.receivedValidJpeg(), is(true)); } finally { IdlingRegistry.getInstance().unregister(resource); resource.close(); } }
Example #16
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 #17
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 #18
Source File: TestUtils.java From Scoops with Apache License 2.0 | 6 votes |
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 #19
Source File: TestUtils.java From espresso-samples with Apache License 2.0 | 6 votes |
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 #20
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 #21
Source File: ExtViewActions.java From PrettyBundle 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 #22
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 #23
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(); } }; }
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 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 #26
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 #27
Source File: MoreViewActions.java From yandex-money-sdk-android with MIT License | 6 votes |
@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 #28
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 #29
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 #30
Source File: ViewActions.java From base_app_android with Apache License 2.0 | 5 votes |
public static ViewAction actionOpenDrawer() { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isAssignableFrom(DrawerLayout.class); } @Override public String getDescription() { return "open drawer"; } @Override public void perform(UiController uiController, View view) { ((DrawerLayout) view).openDrawer(GravityCompat.START); } }; }