Skip to content

Instantly share code, notes, and snippets.

@Ansh1234
Created September 19, 2016 09:31
Show Gist options
  • Save Ansh1234/7f0c80ea5b46c4106cf93e91b342c352 to your computer and use it in GitHub Desktop.
Save Ansh1234/7f0c80ea5b46c4106cf93e91b342c352 to your computer and use it in GitHub Desktop.
public class NestedLayoutActivityTest {
@Rule
public ActivityTestRule mActivityRule = new ActivityTestRule(NestedLayoutActivity.class);
@Test
public void performClickOnTextView() {
onView(withId(R.id.parent_container)).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}
@Override
public String getDescription() {
return "Performing click";
}
@Override
public void perform(UiController uiController, View view) {
//The view which we got in argument is the same view which Espresso found using onView(withId(R.id.parent_container))
LinearLayout parentLinearLayout = (LinearLayout) view;
//Get the LinearLayout inside the LinearLayout
LinearLayout linearLayout = (LinearLayout) parentLinearLayout.getChildAt(0);
//Get the Button inside the inner LinearLayout
TextView helloWordTextView = (TextView) linearLayout.getChildAt(0);
helloWordTextView.performClick();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment