use of androidx.test.espresso.ViewAction in project AntennaPod by AntennaPod.
the class EspressoTestUtils method waitForView.
/**
* Perform action of waiting for a specific view id.
* https://stackoverflow.com/a/49814995/
* @param viewMatcher The view to wait for.
* @param millis The timeout of until when to wait for.
*/
public static ViewAction waitForView(final Matcher<View> viewMatcher, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view for " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
} while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
}
};
}
use of androidx.test.espresso.ViewAction in project collect by opendatakit.
the class ActivityHelpers method getActivity.
public static Activity getActivity() {
final Activity[] currentActivity = new Activity[1];
Espresso.onView(AllOf.allOf(ViewMatchers.withId(android.R.id.content), isDisplayed())).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(View.class);
}
@Override
public String getDescription() {
return "getting text from a TextView";
}
@Override
public void perform(UiController uiController, View view) {
if (view.getContext() instanceof Activity) {
Activity activity1 = (Activity) view.getContext();
currentActivity[0] = activity1;
}
}
});
return currentActivity[0];
}
use of androidx.test.espresso.ViewAction in project Rocket by mozilla-tw.
the class GetTextViewMatcher method getText.
public static 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];
}
use of androidx.test.espresso.ViewAction in project BottomNavigation by Ashok-Varma.
the class Utils method waitId.
/**
* Perform action of waiting for a specific view id.
*/
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
} while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new TimeoutException()).build();
}
};
}
use of androidx.test.espresso.ViewAction in project AntennaPod by AntennaPod.
the class EspressoTestUtils method clickChildViewWithId.
/**
* Perform action of waiting for a specific view id.
* https://stackoverflow.com/a/30338665/
* @param id The id of the child to click.
*/
public static ViewAction clickChildViewWithId(@IdRes 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();
}
};
}
Aggregations