Created
January 27, 2020 20:18
-
-
Save AlexZhukovich/b1d5bab130ca9df268fa3cf3c9bb467f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@LargeTest | |
@RunWith(AndroidJUnit4::class) | |
class SignInActivityTest123 { | |
@Rule | |
@JvmField | |
var mActivityTestRule = ActivityTestRule(SignInActivity::class.java) | |
@Test | |
fun signInActivityTest123() { | |
val appCompatEditText = onView( | |
allOf(withId(R.id.email), | |
childAtPosition( | |
allOf(withId(R.id.signInRoot), | |
childAtPosition( | |
withId(android.R.id.content), | |
0)), | |
4), | |
isDisplayed())) | |
appCompatEditText.perform(replaceText(" test"), closeSoftKeyboard()) | |
val appCompatButton = onView( | |
allOf(withId(R.id.signIn), withText("Sign In"), | |
childAtPosition( | |
allOf(withId(R.id.signInRoot), | |
childAtPosition( | |
withId(android.R.id.content), | |
0)), | |
6), | |
isDisplayed())) | |
appCompatButton.perform(click()) | |
} | |
private fun childAtPosition( | |
parentMatcher: Matcher<View>, position: Int): Matcher<View> { | |
return object : TypeSafeMatcher<View>() { | |
override fun describeTo(description: Description) { | |
description.appendText("Child at position $position in parent ") | |
parentMatcher.describeTo(description) | |
} | |
public override fun matchesSafely(view: View): Boolean { | |
val parent = view.parent | |
return parent is ViewGroup && parentMatcher.matches(parent) | |
&& view == parent.getChildAt(position) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment