Created
December 2, 2015 16:36
-
-
Save TechIsFun/675244e60aa7fd20986a 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
| public class EspressoFriendlyExampleTest { | |
| private static final String TEST_ITEM_TITLE = "A test title"; | |
| private static final String TEST_ITEM_DESCRIPTION = "A test description"; | |
| private static final String TEST_FLAVOUR_TITLE = "A test flavour"; | |
| private static final String TEST_ITEM_COPY_TITLE = "A test copy"; | |
| private static final String TEST_ITEM_COPY_DESCRIPTION = "A test copy description"; | |
| @Override | |
| protected void tearDown() throws Exception { | |
| super.tearDown(); | |
| deleteItem(TEST_ITEM_TITLE); | |
| deleteItem(TEST_ITEM_COPY_TITLE); | |
| deleteFlavour(TEST_FLAVOUR_TITLE); | |
| } | |
| public void testCreateItem() { | |
| loginAsAdmin(); | |
| selectAdminFunction(editorFunction()); | |
| clickOn(addMenuItem()); | |
| editItemName(TEST_ITEM_TITLE); | |
| editItemDescription(TEST_ITEM_DESCRIPTION); | |
| assertUserSees(TEST_ITEM_TITLE); | |
| assertUserSees(TEST_ITEM_DESCRIPTION); | |
| clickOn(firstButton()); | |
| clickOn(secondButton(); | |
| clickOn(saveMenuItem()); | |
| assertUserSees(TEST_ITEM_TITLE); | |
| } | |
| protected void loginAsAdmin() { | |
| onView(withId(R.id.btn_login)).perform(click()); | |
| } | |
| protected void selectAdminFunction(@StringRes int functionName) { | |
| onView(withText(R.string.admin_functions_title)).check(matches(isDisplayed())); | |
| onView(withText(functionName)).perform(click()); | |
| } | |
| protected void clickOn(String text) { | |
| onView(withText(text)).perform(click()); | |
| } | |
| protected void clickOn(@IdRes int viewId) { | |
| onView(withId(viewId)).perform(click()); | |
| } | |
| protected int addMenuItem() { | |
| return R.id.menu_add; | |
| } | |
| protected int firstButton() { | |
| return R.id.btn_first; | |
| } | |
| protected int secondButton() { | |
| return R.id.btn_second; | |
| } | |
| protected void editItemName(String s) { | |
| clickOn(R.id.item_edit_title); | |
| onView(withId(R.id.edittext_edittext)).perform(clearText(), typeText(s), closeSoftKeyboard()); | |
| clickOn(R.id.edittext_ok); | |
| } | |
| protected void editItemDescription(String s) { | |
| clickOn(R.id.item_edit_desc); | |
| onView(withId(R.id.edittext_edittext)).perform(clearText(), typeText(s), closeSoftKeyboard()); | |
| clickOn(R.id.edittext_ok); | |
| } | |
| protected void assertUserSees(@NonNull Object object) { | |
| onView(withText(object.toString())).check(matches(isDisplayed())); | |
| } | |
| protected void assertUserSees(@IdRes int itemId) { | |
| onView(withId(itemId)).check(matches(isDisplayed())); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment