use of androidx.test.espresso.UiController 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.UiController 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.UiController 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.UiController 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();
}
};
}
use of androidx.test.espresso.UiController in project orgzly-android by orgzly.
the class EspressoUtils method setNumber.
public static ViewAction setNumber(final int num) {
return new ViewAction() {
@Override
public void perform(UiController uiController, View view) {
NumberPicker np = (NumberPicker) view;
np.setValue(num);
}
@Override
public String getDescription() {
return "Set the passed number into the NumberPicker";
}
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(NumberPicker.class);
}
};
}
Aggregations