use of android.support.test.espresso.ViewAction in project material-components-android by material-components.
the class NavigationViewActions method setItemTextColor.
/** Sets item text color on the content of the navigation view. */
public static ViewAction setItemTextColor(final ColorStateList textColor) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}
@Override
public String getDescription() {
return "Set item text color";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
NavigationView navigationView = (NavigationView) view;
navigationView.setItemTextColor(textColor);
uiController.loopMainThreadUntilIdle();
}
};
}
use of android.support.test.espresso.ViewAction in project material-components-android by material-components.
the class TabLayoutWithViewPagerTest method addItemsToPager.
private static <Q> ViewAction addItemsToPager(final String[] title, final Q[] content) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(ViewPager.class);
}
@Override
public String getDescription() {
return "Add items and notify on content change";
}
@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();
int itemCount = title.length;
for (int i = 0; i < itemCount; i++) {
viewPagerAdapter.add(title[i], content[i]);
}
viewPagerAdapter.notifyDataSetChanged();
uiController.loopMainThreadUntilIdle();
}
};
}
use of android.support.test.espresso.ViewAction in project iosched by google.
the class MatchersHelper method getNumberOfDescendantsForViewGroupDescendant.
/**
* This returns the number of descendants of the {@code parentViewWithMultipleChildren} that
* have an id of {@code idOfDescendantViewToGetTextFor}}. The parent view is expected to be a
* {@link ViewGroup}. This is used when there is a certain randomness in the elements shown in a
* collection view, even with mock data, but we want to check the number of elements inside the
* parent view.
*
* @see com.google.samples.apps.iosched.explore.ExploreIOActivityTest
*/
public static int getNumberOfDescendantsForViewGroupDescendant(final Matcher<View> parentViewWithMultipleChildren, final int idOfDescendantViewToGetTextFor) {
/**
* We cannot use a int directly as we need to make it final to access it inside the
* inner method but we cannot reassign a value to a final int.
*/
final int[] intHolder = { 0 };
onView(parentViewWithMultipleChildren).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(ViewGroup.class);
}
@Override
public String getDescription() {
return "getting text from a TextView with a known id and that is a descendant of " + "the nth child of a viewgroup";
}
@Override
public void perform(UiController uiController, View view) {
ViewGroup vg = (ViewGroup) view;
int descendants = vg.getChildCount();
for (int i = 0; i < descendants; i++) {
View ithDescendant = vg.getChildAt(i);
View matchedView = ithDescendant.findViewById(idOfDescendantViewToGetTextFor);
if (matchedView != null) {
intHolder[0] += 1;
}
}
}
});
return intHolder[0];
}
use of android.support.test.espresso.ViewAction in project iosched by google.
the class MatchersHelper method getText.
/**
* 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];
}
use of android.support.test.espresso.ViewAction in project ChipsLayoutManager by BelooS.
the class ColumnTest method smoothScrollToPosition_ScrollItemIsVisible_ScrollItemDockedToStartBorder.
@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);
}
Aggregations