Espresso Test Recorder @LargeTest
@RunWith(AndroidJUnit4::class)
class SignInActivityTest {
@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(SignInActivity::class.java)
@Test
fun signInActivityTest() {
Thread.sleep(7000)
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(click())
val appCompatEditText2 = onView(
allOf(withId(R.id.email),
childAtPosition(
allOf(withId(R.id.signInRoot),
childAtPosition(
withId(android.R.id.content),
0)),
4),
isDisplayed()))
appCompatEditText2.perform(replaceText("
[email protected]"), closeSoftKeyboard())
Thread.sleep(7000)
pressBack()
val appCompatButton = onView(
allOf(withId(R.id.signIn), withText("Sing In"),
childAtPosition(
allOf(withId(R.id.signInRoot),
childAtPosition(
withId(android.R.id.content),
0)),
6),
isDisplayed()))
appCompatButton.perform(click())
}
private fun childAtPosition(
parentMatcher: Matcher, position: Int): Matcher {
return object : TypeSafeMatcher() {
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)
}
}
}
}