Created
June 27, 2017 06:54
-
-
Save rohans-doordash/ee6182e9db1c94ec8e29e0d441fa15e2 to your computer and use it in GitHub Desktop.
Login acceptance test
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
package com.dd.doordash; | |
import android.app.Activity; | |
import android.support.test.InstrumentationRegistry; | |
import android.support.test.espresso.IdlingResource; | |
import com.dd.doordash.activities.main.DashboardActivity; | |
public class LoginIdlingResource implements IdlingResource { | |
private ResourceCallback resourceCallback; | |
@Override | |
public String getName() { | |
return LoginIdlingResource.class.getSimpleName(); | |
} | |
@Override | |
public boolean isIdleNow() { | |
Activity activity = ((DoorDashApp) InstrumentationRegistry | |
.getTargetContext().getApplicationContext()).getCurrentActivity(); | |
boolean isIdle = activity != null && activity instanceof DashboardActivity; | |
if (isIdle) { | |
resourceCallback.onTransitionToIdle(); | |
} | |
return isIdle; | |
} | |
@Override | |
public void registerIdleTransitionCallback(ResourceCallback callback) { | |
this.resourceCallback = callback; | |
} | |
} |
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
package com.dd.doordash; | |
import android.content.Intent; | |
import android.support.test.rule.ActivityTestRule; | |
import android.support.test.runner.AndroidJUnit4; | |
import com.dd.doordash.activities.MainActivity; | |
import com.dd.doordash.instruction.PostLoginInstruction; | |
import com.dd.doordash.util.ConditionWatcher; | |
import org.hamcrest.Matchers; | |
import org.junit.Before; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import static android.support.test.espresso.Espresso.onView; | |
import static android.support.test.espresso.action.ViewActions.clearText; | |
import static android.support.test.espresso.action.ViewActions.click; | |
import static android.support.test.espresso.action.ViewActions.typeText; | |
import static android.support.test.espresso.assertion.ViewAssertions.matches; | |
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | |
import static android.support.test.espresso.matcher.ViewMatchers.withId; | |
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue; | |
/** | |
* Test for log in flow. | |
*/ | |
@RunWith(AndroidJUnit4.class) | |
public class LoginTest { | |
private static final String TAG = LoginTest.class.getSimpleName(); | |
@Rule | |
public ActivityTestRule<MainActivity> activityRule | |
= new ActivityTestRule<>(MainActivity.class, false, false); | |
@Before | |
public void setup() { | |
activityRule.launchActivity(new Intent()); | |
} | |
@Test | |
public void login() throws Exception { | |
onView(withId(R.id.login_button)).perform(click()); | |
onView(withTagValue(Matchers.is("login_email"))) | |
.perform(clearText()).perform(typeText("login@example.com")); | |
onView(withTagValue(Matchers.is("login_password"))) | |
.perform(typeText("login-password")); | |
LoginIdlingResource loginIdlingResource = new LoginIdlingResource(); | |
onView(withId(R.id.fragment_login_button)).perform(click()); | |
Espresso.registerIdlingResources(loginIdlingResource); | |
onView(withId(R.id.fab_footer)).check(matches(isDisplayed())); | |
Espresso.unregisterIdlingResources(loginIdlingResource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment