Created
January 29, 2016 03:06
-
-
Save Cronch/8d4bf0e1f3024a0c0fdb to your computer and use it in GitHub Desktop.
Some practical examples of Espresso
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
@Test | |
public void ensureTextChangesWork() { | |
// Type text and then press the button. | |
onView(withId(R.id.inputField)) | |
.perform(typeText("HELLO"), closeSoftKeyboard()); | |
onView(withId(R.id.changeText)).perform(click()); | |
// Check that the text was changed. | |
onView(withId(R.id.inputField)).check(matches(withText("Lalala"))); | |
} | |
@Test | |
public void changeText_newActivity() { | |
// Type text and then press the button. | |
onView(withId(R.id.inputField)).perform(typeText("NewText"), | |
closeSoftKeyboard()); | |
onView(withId(R.id.switchActivity)).perform(click()); | |
// This view is in a different Activity, no need to tell Espresso. | |
onView(withId(R.id.resultView)).check(matches(withText("NewText"))); | |
} | |
@Test | |
public void triggerIntentTest() { | |
// check that the button is there | |
onView(withId(R.id.button)).check(matches(notNullValue())); | |
onView(withId(R.id.button)).check(matches(withText("Start new activity"))); | |
onView(withId(R.id.button)).perform(click()); | |
intended(toPackage("testing.android.sample.com.simpleactivity")); | |
intended(hasExtra("URL", "http://www.sample.com")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment