Skip to content

Instantly share code, notes, and snippets.

@NinoDLC
Created January 29, 2021 17:23
Show Gist options
  • Save NinoDLC/824094aa99bae7ca4f508b1791d51674 to your computer and use it in GitHub Desktop.
Save NinoDLC/824094aa99bae7ca4f508b1791d51674 to your computer and use it in GitHub Desktop.
import android.view.View;
import androidx.annotation.IdRes;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import org.hamcrest.Matcher;
public class ClickChildViewWithId implements ViewAction {
@IdRes
private final int viewId;
public ClickChildViewWithId(@IdRes int viewId) {
this.viewId = viewId;
}
@Override
public Matcher<View> getConstraints() {
return null;
}
@Override
public String getDescription() {
return "Click on a child view with specified id : " + viewId;
}
@Override
public void perform(UiController uiController, View view) {
View v = view.findViewById(viewId);
v.performClick();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment