// Path: app/src/androidTest/java/com/tale/prettybundle/sample/espresso/ExtViewActions.java
// public class ExtViewActions {
// 
//     /**
//      * Perform action of waiting for a specific view id.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitId(R.id.dialogEditor, Sampling.SECONDS_15));
//      *
//      * @param viewId
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitId(final int viewId, final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return isRoot();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 final long startTime = System.currentTimeMillis();
//                 final long endTime = startTime + millis;
//                 final Matcher<View> viewMatcher = withId(viewId);
// 
//                 do {
//                     for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
//                         // found view with required ID
//                         if (viewMatcher.matches(child)) {
//                             return;
//                         }
//                     }
// 
//                     uiController.loopMainThreadForAtLeast(50);
//                 }
//                 while (System.currentTimeMillis() < endTime);
// 
//                 // timeout happens
//                 throw new PerformException.Builder()
//                         .withActionDescription(this.getDescription())
//                         .withViewDescription(HumanReadables.describe(view))
//                         .withCause(new TimeoutException())
//                         .build();
//             }
//         };
//     }
// 
//     /**
//      * Perform action of waiting for a specific time. Useful when you need
//      * to wait for animations to end and Espresso fails at waiting.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitAtLeast(Sampling.SECONDS_15));
//      *
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitAtLeast(final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for at least " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 uiController.loopMainThreadForAtLeast(millis);
//             }
//         };
//     }
// 
//     public static ViewAction waitForSoftKeyboard() {
//         return waitAtLeast(500);
//     }
// 
//     public static ViewAction swipeTop() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
//     }
// 
//     public static ViewAction swipeBottom() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER);
//     }
// 
//     /**
//      * Perform action of waiting until UI thread is free.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitUntilIdle());
//      *
//      * @return
//      */
//     public static ViewAction waitUntilIdle() {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait until UI thread is free";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//             }
//         };
//     }
// 
// }


import android.support.test.espresso.Espresso;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.test.ActivityInstrumentationTestCase2;
import com.tale.prettybundle.sample.espresso.ExtViewActions;
package com.tale.prettybundle.sample;



/**
 * Created by tale on 2/18/15.
 */
public class InjectStringExtrasTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public InjectStringExtrasTest() {
        super(MainActivity.class);
    }

    @Override public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void testStartActivityTestStringExtra2WithExtras() throws Exception {
        final String extra1 = "Giang";
        final String extra2 = "Nguyen";
        Espresso.onView(ViewMatchers.withHint(R.string.string_extra_1)).perform(ViewActions.typeText(extra1), ViewActions.pressImeActionButton());
        Espresso.onView(ViewMatchers.withHint(R.string.string_extra_2)).perform(ViewActions.typeText(extra2), ViewActions.pressImeActionButton());

// Path: app/src/androidTest/java/com/tale/prettybundle/sample/espresso/ExtViewActions.java
// public class ExtViewActions {
// 
//     /**
//      * Perform action of waiting for a specific view id.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitId(R.id.dialogEditor, Sampling.SECONDS_15));
//      *
//      * @param viewId
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitId(final int viewId, final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return isRoot();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 final long startTime = System.currentTimeMillis();
//                 final long endTime = startTime + millis;
//                 final Matcher<View> viewMatcher = withId(viewId);
// 
//                 do {
//                     for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
//                         // found view with required ID
//                         if (viewMatcher.matches(child)) {
//                             return;
//                         }
//                     }
// 
//                     uiController.loopMainThreadForAtLeast(50);
//                 }
//                 while (System.currentTimeMillis() < endTime);
// 
//                 // timeout happens
//                 throw new PerformException.Builder()
//                         .withActionDescription(this.getDescription())
//                         .withViewDescription(HumanReadables.describe(view))
//                         .withCause(new TimeoutException())
//                         .build();
//             }
//         };
//     }
// 
//     /**
//      * Perform action of waiting for a specific time. Useful when you need
//      * to wait for animations to end and Espresso fails at waiting.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitAtLeast(Sampling.SECONDS_15));
//      *
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitAtLeast(final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for at least " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 uiController.loopMainThreadForAtLeast(millis);
//             }
//         };
//     }
// 
//     public static ViewAction waitForSoftKeyboard() {
//         return waitAtLeast(500);
//     }
// 
//     public static ViewAction swipeTop() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
//     }
// 
//     public static ViewAction swipeBottom() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER);
//     }
// 
//     /**
//      * Perform action of waiting until UI thread is free.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitUntilIdle());
//      *
//      * @return
//      */
//     public static ViewAction waitUntilIdle() {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait until UI thread is free";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//             }
//         };
//     }
// 
// }


// Path: app/src/androidTest/java/com/tale/prettybundle/sample/InjectStringExtrasTest.java
import android.support.test.espresso.Espresso;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.test.ActivityInstrumentationTestCase2;
import com.tale.prettybundle.sample.espresso.ExtViewActions;

package com.tale.prettybundle.sample;



/**
 * Created by tale on 2/18/15.
 */
public class InjectStringExtrasTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public InjectStringExtrasTest() {
        super(MainActivity.class);
    }

    @Override public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void testStartActivityTestStringExtra2WithExtras() throws Exception {
        final String extra1 = "Giang";
        final String extra2 = "Nguyen";
        Espresso.onView(ViewMatchers.withHint(R.string.string_extra_1)).perform(ViewActions.typeText(extra1), ViewActions.pressImeActionButton());
        Espresso.onView(ViewMatchers.withHint(R.string.string_extra_2)).perform(ViewActions.typeText(extra2), ViewActions.pressImeActionButton());

        Espresso.onView(ViewMatchers.withText(R.string.submit)).perform(ExtViewActions.waitForSoftKeyboard(), ViewActions.click());