Java Code Examples for android.support.test.espresso.intent.Intents#release()

The following examples show how to use android.support.test.espresso.intent.Intents#release() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Checks if the login is launched when click on logout in nav drawer and click on
 * sign out in alert dialouge box
 */
@Test
public void onClickLogout_ClickSignOut_OpenLoginScreen() throws Exception {

    Intents.init();
    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_logout));

    onView(withId(android.R.id.button1)).perform(click());

    intended(hasComponent(LoginActivity.class.getName()));

    Intents.release();
}
 
Example 2
/**
 * Checks if the usage activity is launched when we click on usage in nav drawer
 */
@Test
public void onClickNavUsage_openUsageActivity() throws Exception {

    Intents.init();

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_usage));

    intended(hasComponent(UsageActivity.class.getName()));

    Intents.release();
}
 
Example 3
/**
 * Check swipes are working on tutorial screens and on last tutorial screen while clicking on
 * GOT IT it should go to login activity
 */
@Test
public void clickingNext_shouldGotoNextTutorial_onClickGotIt_ShouldGoToLoginActivity()
        throws Exception {

    Intents.init();
    onView(withText(R.string.next)).check(matches(isDisplayed()));
    onView(withId(R.id.slide_pager)).perform(swipeLeft());
    onView(withId(R.id.slide_pager)).perform(swipeLeft());
    onView(withId(R.id.slide_pager)).perform(swipeLeft());
    onView(withId(R.id.slide_pager)).perform(swipeLeft());
    onView(withText("SKIP")).check(matches(not(isDisplayed())));
    onView(withText("GOT IT")).check(matches(isDisplayed()));
    onView(withText("GOT IT")).perform(click());
    intended(hasComponent(LoginActivity.class.getName()));
    Intents.release();

}
 
Example 4
/**
 * Checks if alert dialogue box is dismiss when click on cancel in logout alert sign in box
 */
@Test
public void onClickLogout_clickCancel_dismissDialogueBoz() throws Exception {

    Intents.init();
    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_logout));

    onView(withId(android.R.id.button2)).perform(click());

    onView(withId(R.id.drawer_layout))
            .check(matches(isOpen(Gravity.LEFT)));

    Intents.release();
}
 
Example 5
/**
 * Check if the username, password and userAvatar are visible and verify when click on
 * userAvatar UserProfileActivity will open
 */
@Test
public void checkAllViewsVisible_and_OnClickAvatar_openUserProfileActivity() throws Exception {

    Intents.init();
    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    //Please Login first otherwise it will not find username and email
    onView(withId(R.id.nav_user_avatar)).check(matches((isDisplayed())));
    onView(withId(R.id.nav_user_name)).check(matches((isDisplayed())));
    onView(withId(R.id.nav_user_email)).check(matches((isDisplayed())));

    onView(withId(R.id.nav_user_avatar)).perform(click());

    intended(hasComponent(UserProfileActivity.class.getName()));
    Intents.release();
}
 
Example 6
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    activity.finish();
}
 
Example 7
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    resultActivity.finish();
}
 
Example 8
/**
 * Checks while clicking on skip button should start login activity
 */
@Test
public void clickingSkip_shouldStartLoginActivity() throws Exception {

    Intents.init();
    onView(withId(R.id.btn_skip)).perform(click());
    intended(hasComponent(LoginActivity.class.getName()));
    Intents.release();
}
 
Example 9
Source Project: Spork   File: ImmediateIntentsTestRule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			try {
				Intents.init();
				base.evaluate();
			} catch (Exception e) {
				Intents.release();
			}
		}
	};
}
 
Example 10
@After
public void destroy() {
    Intents.release();
}
 
Example 11
Source Project: otp-authenticator   File: MainActivityTest.java    License: MIT License 4 votes vote down vote up
public  void test003AddCodes() throws InterruptedException {
    for(String[] code: codes){
        Intents.init();

        String qr = "otpauth://totp/"+code[0] +"?secret="+new String(new Base32().encode(code[1].getBytes())) ;

        // Build a result to return from the ZXING app
        Intent resultData = new Intent();
        resultData.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, qr);
        Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);

        // Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
        // with the ActivityResult we just created
        intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);

        // Now that we have the stub in place, click on the button in our app that launches into the Camera
        onView(withId(R.id.action_scan)).perform(click());

        // We can also validate that an intent resolving to the "camera" activity has been sent out by our app
        intended(hasAction("com.google.zxing.client.android.SCAN"));

        onView(withText("Account added")).check(matches(isDisplayed()));

        Intents.release();
    }

    Thread.sleep(500);


    for(int i = 0; i < codes.length; i++){
        onData(anything()).inAdapterView(withId(R.id.listView))
                .atPosition(i)
                .onChildView(withId(R.id.textViewLabel))
                .check(matches(withText(codes[i][0])));

        String otp = TOTPHelper.generate(codes[i][1].getBytes());

        onData(anything()).inAdapterView(withId(R.id.listView))
                .atPosition(i)
                .onChildView(withId(R.id.textViewOTP))
                .check(matches(withText(otp)));
    }
}
 
Example 12
@SuppressWarnings("UnusedParameters")
@After
public static void after(Scenario scenario) {
    ActivityUtils.finishOpenActivities();
    Intents.release();
}
 
Example 13
@Override
protected void afterActivityFinished() {
    super.afterActivityFinished();
    Intents.release();
}
 
Example 14
Source Project: AndroidSchool   File: ApplicationTest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
    Intents.release();
}
 
Example 15
@After
public void releaseIntents() {
    Intents.release();
}
 
Example 16
Source Project: otp-authenticator   File: MainActivityTest.java    License: MIT License 4 votes vote down vote up
public void test002NocodeScanned() throws InterruptedException {
    Intents.init();

    // Build a result to return from the ZXING app
    Intent resultData = new Intent();

    Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, resultData);

    // Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
    // with the ActivityResult we just created
    intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);

    // Now that we have the stub in place, click on the button in our app that launches into the Camera
    onView(withId(R.id.action_scan)).perform(click());

    // We can also validate that an intent resolving to the "camera" activity has been sent out by our app
    intended(hasAction("com.google.zxing.client.android.SCAN"));

    onView(withText("No account has been added yet")).check(matches(isDisplayed()));

    Intents.release();
}
 
Example 17
@After
public void releaseIntents() {
    Intents.release();
}
 
Example 18
Source Project: kaif-android   File: HomeActivityTest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
  Intents.release();
}
 
Example 19
Source Project: kaif-android   File: LoginActivityTest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
  Intents.release();
}
 
Example 20
Source Project: otp-authenticator   File: MainActivityTest.java    License: MIT License 3 votes vote down vote up
public void test000EmptyStart() throws InterruptedException {

        onView(withText("No account has been added yet")).check(matches(isDisplayed()));
        onView(withText("Add")).check(matches(isDisplayed()));

        Intents.init();

        String qr = "XXX" ;

        // Build a result to return from the ZXING app
        Intent resultData = new Intent();
        resultData.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, qr);
        Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);

        // Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
        // with the ActivityResult we just created
        intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);


        onView(withText("Add")).check(matches(isDisplayed()));

        onView(withText("Add")).perform(click());

        // We can also validate that an intent resolving to the "camera" activity has been sent out by our app
        intended(hasAction("com.google.zxing.client.android.SCAN"));


        Intents.release();
    }