android.support.test.espresso.intent.Intents源码实例Demo

类android.support.test.espresso.intent.Intents源码实例Demo

下面列出了android.support.test.espresso.intent.Intents 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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));
}
 
源代码2 项目: polling-station-app   文件: TestResultActivity.java
@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);
}
 
源代码3 项目: polling-station-app   文件: TestElectionChoice.java
@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));
}
 
/**
 * 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();
}
 
/**
 * 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();
}
 
/**
 * 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();
}
 
/**
 * 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();
}
 
/**
 * 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();

}
 
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    activity.finish();
}
 
源代码10 项目: polling-station-app   文件: TestResultActivity.java
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    resultActivity.finish();
}
 
源代码11 项目: polling-station-app   文件: TestElectionChoice.java
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    electionActivity.finish();
}
 
源代码12 项目: Spork   文件: ImmediateIntentsTestRule.java
@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();
			}
		}
	};
}
 
源代码13 项目: AndroidSchool   文件: RepositoriesActivityTest.java
@Test
public void testClickOnItem() throws Exception {
    onView(withId(R.id.recyclerView))
            .perform(actionOnItemAtPosition(14, click()));

    Intents.intended(hasComponent(CommitsActivity.class.getName()));
}
 
源代码14 项目: AndroidSchool   文件: RepositoriesActivityTest.java
@After
public void tearDown() throws Exception {
    Intents.release();
    if (idlingResource != null) {
        Espresso.unregisterIdlingResources(idlingResource);
    }
    RepositoryProvider.provideKeyValueStorage().clear();
    Realm.getDefaultInstance().executeTransaction(realm -> realm.deleteAll());
}
 
源代码15 项目: AndroidSchool   文件: AuthActivityTest.java
@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);

}
 
源代码16 项目: kaif-android   文件: HomeActivityTest.java
@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();
}
 
源代码17 项目: kaif-android   文件: LoginActivityTest.java
@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();
}
 
/**
 * 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();
}
 
/**
 * 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();
}
 
@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();
}
 
@Before
public void setUp() {
    Intents.init();
}
 
@After
public void destroy() {
    Intents.release();
}
 
源代码23 项目: polling-station-app   文件: TestMainActivity.java
@Before
public void setUp() {
    Intents.init();
}
 
源代码24 项目: polling-station-app   文件: TestMainActivity.java
@After
public void destroy() {
    Intents.release();
}
 
源代码25 项目: android-sdk   文件: GalleryHelperTest.java
@Before
public void initializeIntents() {
  Intents.init();
}
 
源代码26 项目: android-sdk   文件: GalleryHelperTest.java
@After
public void releaseIntents() {
  Intents.release();
}
 
源代码27 项目: android-sdk   文件: CameraHelperTest.java
@Before
public void initializeIntents() {
  Intents.init();
}
 
源代码28 项目: android-sdk   文件: CameraHelperTest.java
@After
public void releaseIntents() {
  Intents.release();
}
 
@SuppressWarnings("UnusedParameters")
@After
public static void after(Scenario scenario) {
    ActivityUtils.finishOpenActivities();
    Intents.release();
}
 
@Override
protected void afterActivityLaunched() {
    Intents.init();
    super.afterActivityLaunched();
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法