android.support.test.espresso.intent.Intents Java Examples

The following examples show how to use android.support.test.espresso.intent.Intents. 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
Source File: ElectionChoiceActivityTest.java    From polling-station-app with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() {
    Intents.init();

    // Wait till the splashactivity is closed, indicating blockchain was instantiated has started
    Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    mActivityRule.launchActivity(new Intent(targetContext, ElectionChoiceActivity.class));
    while (!mActivityRule.getActivity().isFinishing()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    activity = (ElectionChoiceActivity) mElectionActivityRule.launchActivity(new Intent(targetContext, ElectionChoiceActivity.class));
}
 
Example #2
Source File: DashboardActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #3
Source File: DashboardActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: DashboardActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: DashboardActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: TestElectionChoice.java    From polling-station-app with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() {
    Intents.init();

    // Wait till the splashactivity is closed, indicating blockchain was instantiated has started
    Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    mActivityRule.launchActivity(new Intent(targetContext, SplashActivity.class));
    while (!mActivityRule.getActivity().isFinishing()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    electionActivity = (ElectionChoiceActivity) mElectionActivityRule.launchActivity(new Intent(targetContext, ElectionChoiceActivity.class));
}
 
Example #7
Source File: TutorialActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #8
Source File: TestResultActivity.java    From polling-station-app with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() {
    Intents.init();

    // Wait till the splashactivity is closed, indicating blockchain was instantiated has started
    Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    splashActivityRule.launchActivity(new Intent(targetContext, SplashActivity.class));
    while (!splashActivityRule.getActivity().isFinishing()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    Context targetContext2 = InstrumentationRegistry.getInstrumentation()
            .getTargetContext();
    Intent intent = new Intent(targetContext2, ResultActivity.class);
    intent.putExtra("pubKey", pubKey);
    intent.putExtra("voter", voter);
    resultActivity = (ResultActivity) activityRule.launchActivity(intent);
}
 
Example #9
Source File: TutorialActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #10
Source File: TutorialActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
/**
 * First it swipes two times and then swipe back. Then this test will check while clicking
 * on the skip button should go the login activity
 */
@Test
public void swipeRightLeft_clickOnSkip_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(swipeRight());
    onView(withText("SKIP")).check(matches(isDisplayed()));
    onView(withId(R.id.btn_skip)).perform(click());
    intended(hasComponent(LoginActivity.class.getName()));
    Intents.release();
}
 
Example #11
Source File: TestMainActivityWithEspresso.java    From vb-android-app-quality with Apache License 2.0 5 votes vote down vote up
@Override
public void testThatDefaultBehaviorIsWorking() throws Exception {
    Instrumentation.ActivityResult dummyResult = new Instrumentation.ActivityResult(0, null);
    Intents.intending(allOf(
            hasAction(Intent.ACTION_SEND),
            IntentMatchers.hasExtra(Intent.EXTRA_SUBJECT, mActivityRule.getActivity().getString(R.string.share_title))))
            .respondWith(dummyResult);
    super.testThatDefaultBehaviorIsWorking();
}
 
Example #12
Source File: ElectionChoiceActivityTest.java    From polling-station-app with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    activity.finish();
}
 
Example #13
Source File: LoginActivityTest.java    From kaif-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
  KaifApplication app = (KaifApplication) instrumentation.getTargetContext()
      .getApplicationContext();
  TestBeans beans = DaggerTestBeans.builder().build();
  app.setBeans(beans);
  beans.inject(this);
  Intents.init();
}
 
Example #14
Source File: HomeActivityTest.java    From kaif-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
  KaifApplication app = (KaifApplication) instrumentation.getTargetContext()
      .getApplicationContext();
  TestBeans beans = DaggerTestBeans.builder().build();
  app.setBeans(beans);
  beans.inject(this);
  Intents.init();
}
 
Example #15
Source File: AuthActivityTest.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuccessAuth() throws Exception {
    onView(withId(R.id.loginEdit)).perform(typeText("login"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordEdit)).perform(typeText("pass"));
    closeSoftKeyboard();
    onView(withId(R.id.logInButton)).perform(click());

    IdlingResource idlingResource = TimeIdlingResource.timeout(4000);
    Intents.intended(hasComponent(RepositoriesActivity.class.getName()));
    Espresso.unregisterIdlingResources(idlingResource);

}
 
Example #16
Source File: RepositoriesActivityTest.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    Intents.release();
    if (idlingResource != null) {
        Espresso.unregisterIdlingResources(idlingResource);
    }
    RepositoryProvider.provideKeyValueStorage().clear();
    Realm.getDefaultInstance().executeTransaction(realm -> realm.deleteAll());
}
 
Example #17
Source File: RepositoriesActivityTest.java    From AndroidSchool with Apache License 2.0 5 votes vote down vote up
@Test
public void testClickOnItem() throws Exception {
    onView(withId(R.id.recyclerView))
            .perform(actionOnItemAtPosition(14, click()));

    Intents.intended(hasComponent(CommitsActivity.class.getName()));
}
 
Example #18
Source File: TestResultActivity.java    From polling-station-app with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    resultActivity.finish();
}
 
Example #19
Source File: TestElectionChoice.java    From polling-station-app with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    electionActivity.finish();
}
 
Example #20
Source File: ImmediateIntentsTestRule.java    From Spork with 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 #21
Source File: SnippetListActivityTests.java    From android-java-snippets-sample with MIT License 4 votes vote down vote up
@After
public void releaseIntents() {
    Intents.release();
}
 
Example #22
Source File: TestManualInputActivity.java    From polling-station-app with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() {
    Intents.init();
}
 
Example #23
Source File: TestManualInputActivity.java    From polling-station-app with GNU Lesser General Public License v3.0 4 votes vote down vote up
@After
public void destroy() {
    Intents.release();
}
 
Example #24
Source File: TestMainActivity.java    From polling-station-app with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() {
    Intents.init();
}
 
Example #25
Source File: TestMainActivity.java    From polling-station-app with GNU Lesser General Public License v3.0 4 votes vote down vote up
@After
public void destroy() {
    Intents.release();
}
 
Example #26
Source File: GalleryHelperTest.java    From android-sdk with Apache License 2.0 4 votes vote down vote up
@Before
public void initializeIntents() {
  Intents.init();
}
 
Example #27
Source File: MainActivityTest.java    From otp-authenticator with 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 #28
Source File: MainActivityTest.java    From otp-authenticator with 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 #29
Source File: LoginActivityTest.java    From kaif-android with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
  Intents.release();
}
 
Example #30
Source File: GalleryHelperTest.java    From android-sdk with Apache License 2.0 4 votes vote down vote up
@After
public void releaseIntents() {
  Intents.release();
}