Java Code Examples for android.support.test.espresso.ViewAction

The following are top voted examples for showing how to use android.support.test.espresso.ViewAction. 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: fullscreen-video-view   File: CustomChecks.java   View source code 7 votes vote down vote up
static ViewAction clickNoConstraints() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isEnabled(); // No constraints, isEnabled and isClickable are checked
        }

        @Override
        public String getDescription() {
            return "Click a view with no constraints.";
        }

        @Override
        public void perform(UiController uiController, View view) {
            view.performClick();
        }
    };
}
 
Example 2
Project: starwarsshop   File: MyViewAction.java   View source code 7 votes vote down vote up
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);
            v.performClick();
        }
    };
}
 
Example 3
Project: GitHub   File: StartupTest.java   View source code 6 votes vote down vote up
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 4
Project: GitHub   File: StartupTest.java   View source code 6 votes vote down vote up
public static ViewAction loopMainThreadFor(final long millis) {
	return new ViewAction() {

		@Override
		public Matcher<View> getConstraints() {
			return isEnabled();
		}

		@Override
		public String getDescription() {
			return "Rturns an action that loops the main thread for at least " + millis +"ms.";
		}

		@Override
		public void perform(final UiController uiController, final View view) {
			uiController.loopMainThreadForAtLeast(millis);
		}
	};
}
 
Example 5
Project: GitHub   File: PubkeyListActivityTest.java   View source code 6 votes vote down vote up
private ViewAction fillEntropy() {
	return new ViewAction() {
		@Override
		public Matcher<View> getConstraints() {
			return allOf(isDisplayed(), isAssignableFrom(EntropyView.class));
		}

		@Override
		public String getDescription() {
			return "Dismisses the 'Gathering entropy...' dialog";
		}

		@Override
		public void perform(final UiController uiController, final View view) {
			((EntropyView) view).notifyListeners();
		}
	};
}
 
Example 6
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 7
Project: android-PictureInPicture   File: MediaSessionPlaybackActivityTest.java   View source code 6 votes vote down vote up
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 8
Project: android-PictureInPicture   File: MainActivityTest.java   View source code 6 votes vote down vote up
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 9
Project: DiscogsBrowser   File: TestUtils.java   View source code 6 votes vote down vote up
/**
 * From: http://stackoverflow.com/questions/33505953/espresso-how-to-test-swiperefreshlayout/33516360#33516360
 * <p>
 * ViewPager will throw an error if not 90% of it is displayed. This reduces the restriction.
 *
 * @param action      Action to be done.
 * @param constraints Restrictions on the view.
 * @return Performs an action on the view.
 */
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints)
{
    return new ViewAction()
    {
        @Override
        public Matcher<View> getConstraints()
        {
            return constraints;
        }

        @Override
        public String getDescription()
        {
            return action.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view)
        {
            action.perform(uiController, view);
        }
    };
}
 
Example 10
Project: fullscreen-video-view   File: CustomChecks.java   View source code 6 votes vote down vote up
static ViewAction setOrientation(final int orientation) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {
            return "Change orientation";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            changeOrientation(view, orientation);
        }
    };
}
 
Example 11
Project: PXLSRT   File: CameraViewActions.java   View source code 6 votes vote down vote up
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 12
Project: ChimpCheck   File: FingerGestures.java   View source code 6 votes vote down vote up
public static ViewAction swipeOnCoord(final float fromX, final float fromY, final float toX, final float toY) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {

            return "Swipe from" + fromX + ", " + fromY + " to " + toX + ", " + toY;
        }

        @Override
        public void perform(UiController uiController, final View view) {
            drag(fromX, fromY, toX, toY);
        }
    };
}
 
Example 13
Project: ommvplib   File: TestHelper.java   View source code 6 votes vote down vote up
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 14
Project: polling-station-app   File: TestMainActivity.java   View source code 6 votes vote down vote up
/**
 * 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 15
Project: orgzly-android   File: EspressoUtils.java   View source code 6 votes vote down vote up
/**
 * Set value for {@link NumberPicker}
 */
public static ViewAction setNumber(final int n) {
    return new ViewAction() {
        @Override
        public void perform(UiController uiController, View view) {
            ((NumberPicker) view).setValue(n);
        }

        @Override
        public String getDescription() {
            return "Set NumberPicker value";
        }

        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(NumberPicker.class);
        }
    };
}
 
Example 16
Project: ChipsLayoutManager   File: ColumnTest.java   View source code 6 votes vote down vote up
@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 17
Project: ChipsLayoutManager   File: ColumnTest.java   View source code 6 votes vote down vote up
@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 18
Project: ChipsLayoutManager   File: RowTest.java   View source code 6 votes vote down vote up
@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 19
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 20
Project: Ristretto   File: OnViewAllOfWithIsDisplayedNoImport.java   View source code 6 votes vote down vote up
public void fooAllOf() {
    Espresso.onView(AllOf.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    
    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
}
 
Example 21
Project: Ristretto   File: OnViewAllOfWithIsDisplayedNoImport.java   View source code 6 votes vote down vote up
public void fooMatchers() {
    Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());

    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
}
 
Example 22
Project: Ristretto   File: OnViewAllOfWithIsDisplayedNoImport.java   View source code 6 votes vote down vote up
public void fooCoreMatchers() {
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());

    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
}
 
Example 23
Project: Mixtape   File: RecyclerBodyViewViewActions.java   View source code 6 votes vote down vote up
public static ViewAction scrollToStart() {
	return new ViewAction() {
		@Override
		public Matcher<View> getConstraints() {
			return isAssignableFrom(RecyclerBodyView.class);
		}

		@Override
		public String getDescription() {
			return "scroll to start";
		}

		@Override
		public void perform(final UiController uiController, final View view) {
			((RecyclerBodyView) view).showItem(0);
		}
	};
}
 
Example 24
Project: Mixtape   File: RecyclerBodyViewViewActions.java   View source code 6 votes vote down vote up
public static ViewAction scrollToEnd() {
	return new ViewAction() {
		@Override
		public Matcher<View> getConstraints() {
			return isAssignableFrom(RecyclerBodyView.class);
		}

		@Override
		public String getDescription() {
			return "scroll to end";
		}

		@Override
		public void perform(final UiController uiController, final View view) {
			final RecyclerBodyView castView = (RecyclerBodyView) view;
			castView.showItem(castView.getItems().size() - 1);
		}
	};
}
 
Example 25
Project: EncryptAndroidSample   File: ExampleInstrumentedTest.java   View source code 6 votes vote down vote up
/**
 * Try to getText from TextView
 */
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 26
Project: firefox-tv   File: PullDownToRefreshTest.java   View source code 6 votes vote down vote up
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return constraints;
        }

        @Override
        public String getDescription() {
            return action.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view) {
            action.perform(uiController, view);
        }
    };
}
 
Example 27
Project: espresso-doppio   File: DoppioActions.java   View source code 6 votes vote down vote up
/**
 * Action that does nothing
 * <p/>
 * Useful for waiting for idle sync. In some cases waiting for IdlingResource to be idle is
 * crucial for some sync code execution, for example assertions.
 * <p/>
 * Usage:
 * //register desired IdlingResource
 * onView(withText("Yes")).perform(DoppioActions.noAction()); //espresso will stay here until idle
 *
 * @return new ViewAction that does nothing
 */
public static ViewAction noAction() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return Matchers.any(View.class);
        }

        @Override
        public String getDescription() {
            return "Performs no action, just to satisfy idling resources";
        }

        @Override
        public void perform(UiController uiController, View view) {

        }
    };
}
 
Example 28
Project: material-components-android   File: TextInputLayoutActions.java   View source code 6 votes vote down vote up
public static ViewAction setCounterEnabled(final boolean enabled) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the counter enabled";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setCounterEnabled(enabled);
    }
  };
}
 
Example 29
Project: device-info   File: EspressoUtils.java   View source code 6 votes vote down vote up
public static ViewAction checkAttributionView(String library, String author, String description, String license) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return null;
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView txtLibrary = ButterKnife.findById(view, R.id.txt_attribution_library);
            TextView txtAuthor = ButterKnife.findById(view, R.id.txt_attribution_author);
            TextView txtDescription = ButterKnife.findById(view, R.id.txt_attribution_description);
            TextView txtLicense = ButterKnife.findById(view, R.id.txt_attribution_license);

            assertThat(txtLibrary).containsText(library);
            assertThat(txtAuthor).containsText(author);
            assertThat(txtDescription).containsText(description);
            assertThat(txtLicense).containsText(license);
        }
    };
}
 
Example 30
Project: material-components-android   File: ViewPagerActions.java   View source code 6 votes vote down vote up
/** Moves <code>ViewPager</code> to specific page. */
public static ViewAction scrollToPage(final int page) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isDisplayingAtLeast(90);
    }

    @Override
    public String getDescription() {
      return "ViewPager move to a specific page";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      ViewPager viewPager = (ViewPager) view;
      viewPager.setCurrentItem(page, false);

      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example 31
Project: material-components-android   File: TextInputLayoutActions.java   View source code 6 votes vote down vote up
public static ViewAction setHelperTextTextAppearance(final int resId) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the helper text appearance";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setHelperTextTextAppearance(resId);
    }
  };
}
 
Example 32
Project: nuclei-android   File: OffsetAdapterTests2.java   View source code 6 votes vote down vote up
public static ViewAction scrollToPosition(final int position) {
    return new ViewAction() {
        @SuppressWarnings("unchecked")
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(RecyclerView.class);
        }

        @Override
        public void perform(UiController uiController, View view) {
            ((RecyclerView) view).scrollToPosition(position);
        }

        @Override
        public String getDescription() {
            return "scroll to";
        }
    };
}
 
Example 33
Project: cameraview   File: CameraViewActions.java   View source code 6 votes vote down vote up
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 34
Project: bigbang   File: ViewActions.java   View source code 6 votes vote down vote up
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return constraints;
    }

    @Override
    public String getDescription() {
      return action.getDescription();
    }

    @Override
    public void perform(UiController uiController, View view) {
      action.perform(uiController, view);
    }
  };
}
 
Example 35
Project: bigbang   File: MaterialPickerDialogActions.java   View source code 6 votes vote down vote up
public static ViewAction setTime(final int hours, final int minutes) {
  return new ViewAction() {
    @Override
    public void perform(UiController uiController, View view) {
      final RadialPickerLayout timePicker = (RadialPickerLayout) view;

      timePicker.setTime(new Timepoint(hours, minutes, 0));
    }

    @Override
    public String getDescription() {
      return "set time";
    }

    @Override
    public Matcher<View> getConstraints() {
      return allOf(isAssignableFrom(RadialPickerLayout.class), isDisplayed());
    }
  };
}
 
Example 36
Project: material-components-android   File: TextInputLayoutActions.java   View source code 6 votes vote down vote up
public static ViewAction setErrorEnabled(final boolean enabled) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Enables/disables the error";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setErrorEnabled(enabled);
    }
  };
}
 
Example 37
Project: material-components-android   File: TextInputLayoutActions.java   View source code 6 votes vote down vote up
public static ViewAction setBoxBackgroundColor(@ColorInt final int backgroundColor) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the box's background color";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setBoxBackgroundColor(backgroundColor);
    }
  };
}
 
Example 38
Project: Voluminotes-App   File: MainActivityTest.java   View source code 6 votes vote down vote up
private 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);
        }
    };
}
 
Example 39
Project: sunny-reader   File: ViewActionUtils.java   View source code 6 votes vote down vote up
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return constraints;
        }

        @Override
        public String getDescription() {
            return action.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view) {
            action.perform(uiController, view);
        }
    };
}
 
Example 40
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);
}