Created
September 19, 2016 09:31
-
-
Save Ansh1234/7f0c80ea5b46c4106cf93e91b342c352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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