android.support.test.espresso.IdlingResource Java Examples

The following examples show how to use android.support.test.espresso.IdlingResource. 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 Project: mangosta-android   Author: esl   File: LoginInstrumentedTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void checkXMPPLoggedUserSaved() throws Exception {
    assumeTrue(isUserLoggedIn());

    IdlingResource resource = startTiming(SplashActivity.WAIT_TIME);

    assumeNotNull(XMPPSession.getInstance().getXMPPConnection());
    assumeNotNull(XMPPSession.getInstance().getXMPPConnection().getUser());

    Jid jid = XMPPSession.getInstance().getXMPPConnection().getUser().asBareJid();
    assertTrue(XMPPUtils.isAutenticatedJid(jid));

    String userName = XMPPUtils.fromJIDToUserName(jid.toString());
    assertTrue(XMPPUtils.isAutenticatedUser(userName));

    stopTiming(resource);
}
 
Example #2
Source Project: okhttp-idling-resource   Author: JakeWharton   File: OkHttp3IdlingResourceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void idleCallback() throws InterruptedException, IOException {
  server.enqueue(new MockResponse());

  OkHttpClient client = new OkHttpClient();
  IdlingResource idlingResource = OkHttp3IdlingResource.create("Ok!", client);

  final AtomicInteger count = new AtomicInteger();
  IdlingResource.ResourceCallback callback = new IdlingResource.ResourceCallback() {
    @Override public void onTransitionToIdle() {
      count.getAndIncrement();
    }
  };
  idlingResource.registerIdleTransitionCallback(callback);

  assertThat(count.get()).isEqualTo(0);

  // Use a synchronous call as a quick way to transition from busy to idle in a blocking way.
  client.newCall(new Request.Builder().url(server.url("/")).build()).execute().close();
  assertThat(count.get()).isEqualTo(1);
}
 
Example #3
Source Project: iroha-android   Author: hyperledger   File: RegistrationIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void register_existingUsername() {
    onView(withId(R.id.username)).perform(typeText(EXISTING_USERNAME), closeSoftKeyboard());
    onView(withId(R.id.register_button)).perform(click());

    IdlingPolicies.setIdlingResourceTimeout(NETWORK_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    IdlingPolicies.setMasterPolicyTimeout(NETWORK_TIMEOUT_SECONDS * 2, TimeUnit.SECONDS);

    IdlingResource idlingResource = new NetworkRequestIdlingResources(rule.getActivity().registrationPresenter);
    IdlingRegistry.getInstance().register(idlingResource);

    onView(withText(R.string.error_dialog_title))
            .inRoot(isDialog())
            .check(matches(isDisplayed()));

    onView(withText(R.string.username_already_exists_error_dialog_message))
            .inRoot(isDialog())
            .check(matches(isDisplayed()));

    onView(withText(android.R.string.ok))
            .inRoot(isDialog())
            .check(matches(isDisplayed()));

    IdlingRegistry.getInstance().unregister(idlingResource);
}
 
Example #4
Source Project: SuntimesWidget   Author: forrestguice   File: SuntimesScreenshots1.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void makeScreenshots0(Context context, String languageTag, String theme)
{
    SuntimesTestConfig configuration = defaultConfig;
    if (config.containsKey(languageTag)) {
        configuration = config.get(languageTag);
    }
    configureAppForTesting(context, languageTag, configuration, theme);

    activityRule.getActivity().finish();
    activityRule.launchActivity(activityRule.getActivity().getIntent());
    onView( withId(android.R.id.content)).perform(ViewActions.swipeUp());

    long waitTime = 6 * 1000;            // wait a moment
    IdlingResource waitForResource = new ElapsedTimeIdlingResource(waitTime);
    IdlingPolicies.setMasterPolicyTimeout(waitTime * 2, TimeUnit.MILLISECONDS);
    IdlingPolicies.setIdlingResourceTimeout(waitTime * 2, TimeUnit.MILLISECONDS);
    registerIdlingResources(waitForResource);

    captureScreenshot(activityRule.getActivity(), version + "/" + languageTag, "activity-alarms0-" + theme);
    unregisterIdlingResources(waitForResource);
}
 
Example #5
Source Project: SuntimesWidget   Author: forrestguice   File: SuntimesScreenshots.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void makeScreenshots0(Context context, String languageTag, String theme)
{
    SuntimesTestConfig configuration = defaultConfig;
    if (config.containsKey(languageTag)) {
        configuration = config.get(languageTag);
    }

    configureAppForTesting(context, languageTag, configuration, theme);
    activityRule.launchActivity(activityRule.getActivity().getIntent());

    long waitTime = 3 * 1000;            // wait a moment
    IdlingResource waitForResource = new ElapsedTimeIdlingResource(waitTime);
    IdlingPolicies.setMasterPolicyTimeout(waitTime * 2, TimeUnit.MILLISECONDS);
    IdlingPolicies.setIdlingResourceTimeout(waitTime * 2, TimeUnit.MILLISECONDS);
    registerIdlingResources(waitForResource);

    captureScreenshot(activityRule.getActivity(), version + "/" + languageTag, "activity-main0-" + theme);

    unregisterIdlingResources(waitForResource);
}
 
Example #6
Source Project: mangosta-android   Author: esl   File: LoginInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void checkXMPPServerAndServiceInLogin() throws Exception {
    assumeFalse(isUserLoggedIn());

    IdlingResource resource = startTiming(SplashActivity.WAIT_TIME);

    onView(withId(R.id.loginJidCompletionEditText))
            .check(matches(withText("@" + XMPPSession.SERVICE_NAME)));

    onView(withId(R.id.loginServerEditText))
            .check(matches(withText(XMPPSession.SERVER_NAME)));

    stopTiming(resource);
}
 
Example #7
Source Project: mangosta-android   Author: esl   File: MainMenuInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void logoutWithMenuItem() throws Exception {
    assumeTrue(isUserLoggedIn());

    openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());

    onView(withText(R.string.action_signout))
            .check(matches(isDisplayed()))
            .check(matches(isEnabled()))
            .perform(click());

    IdlingResource resource = startTiming(SplashActivity.WAIT_TIME);
    onView(withId(R.id.loginButton)).check(matches(isDisplayed()));
    stopTiming(resource);
}
 
Example #8
Source Project: iroha-android   Author: hyperledger   File: RegistrationIntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void register_validUsername() {
    onView(withId(R.id.username)).perform(typeText(username), closeSoftKeyboard());
    onView(withId(R.id.register_button)).perform(click());

    IdlingPolicies.setIdlingResourceTimeout(NETWORK_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    IdlingPolicies.setMasterPolicyTimeout(NETWORK_TIMEOUT_SECONDS * 2, TimeUnit.SECONDS);

    IdlingResource idlingResource = new NetworkRequestIdlingResources(rule.getActivity().registrationPresenter);
    IdlingRegistry.getInstance().register(idlingResource);

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

    IdlingRegistry.getInstance().unregister(idlingResource);
}
 
Example #9
Source Project: AndroidSchool   Author: ArturVasilov   File: AuthActivityTest.java    License: 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 #10
Source Project: AndroidSchool   Author: ArturVasilov   File: AuthActivityTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testErrorAuth() throws Exception {
    RepositoryProvider.provideKeyValueStorage().saveToken(ERROR);

    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);
    onView(withId(R.id.loginInputLayout)).check(matches(withInputError(R.string.error)));
    Espresso.unregisterIdlingResources(idlingResource);
}
 
Example #11
Source Project: mockwebserver-demo   Author: chiuki   File: OkHttpIdlingResourceRule.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 {
      IdlingResource idlingResource = OkHttp3IdlingResource.create(
          "okhttp", OkHttp.getInstance());
      Espresso.registerIdlingResources(idlingResource);

      base.evaluate();

      Espresso.unregisterIdlingResources(idlingResource);
    }
  };
}
 
Example #12
Source Project: SuntimesWidget   Author: forrestguice   File: SuntimesActivityTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void userSwappedCard()
{
    Matcher<View> cardFlipper = withId(R.id.info_time_flipper1);
    onView(cardFlipper).check(assertShown);   // flipper should be visible

    boolean cardSetToToday = viewIsDisplayed(R.id.info_time_all_today, "Today");

    // pre-click checks
    if (cardSetToToday)
        verifyTimeCard_today();
    else verifyTimeCard_tomorrow();

    // click the next/prev button
    if (cardSetToToday)
        swapCardNext();
    else swapCardPrev();

    cardSetToToday = !cardSetToToday;

    // post-click checks
    if (cardSetToToday)
        verifyTimeCard_today();
    else verifyTimeCard_tomorrow();

    // wait a minute (and check again)
    long waitTime = 60 * 1000;
    IdlingResource waitForResource = new ElapsedTimeIdlingResource(waitTime);
    IdlingPolicies.setMasterPolicyTimeout(waitTime * 2, TimeUnit.MILLISECONDS);
    IdlingPolicies.setIdlingResourceTimeout(waitTime * 2, TimeUnit.MILLISECONDS);

    // during that minute
    // the app will update the clock and note area at least once

    registerIdlingResources(waitForResource);       // afterward...
    verifyTimeCard_today();
    unregisterIdlingResources(waitForResource);
}
 
Example #13
Source Project: testing-cin   Author: damorim   File: MainActivity.java    License: MIT License 5 votes vote down vote up
/**
 * Only called from test, creates and returns a new {@link SimpleIdlingResource}.
 */
@VisibleForTesting
@NonNull
public IdlingResource getIdlingResource() {
    if (mIdlingResource == null) {
        mIdlingResource = new SimpleIdlingResource();
    }
    return mIdlingResource;
}
 
Example #14
Source Project: dev-summit-architecture-demo   Author: yigit   File: FeedActivityTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void registerIdlingResource() {
    mIdlingResource = new IdlingResource() {
        ResourceCallback mResourceCallback;

        @Override
        public String getName() {
            return "RecyclerView";
        }

        @Override
        public boolean isIdleNow() {
            boolean idle = !mCreatedActivity ||
                    !getActivity().mBinding.list.hasPendingAdapterUpdates();
            if (idle && mResourceCallback != null) {
                mResourceCallback.onTransitionToIdle();
            }
            return idle;
        }

        @Override
        public void registerIdleTransitionCallback(ResourceCallback callback) {
            mResourceCallback = callback;
        }
    };
    Espresso.registerIdlingResources(mIdlingResource);
}
 
Example #15
Source Project: Awesome-WanAndroid   Author: JsonChao   File: AbstractSimpleActivity.java    License: Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public IdlingResource getCountingIdlingResource() {
    return EspressoIdlingResource.getIdlingResource();
}
 
Example #16
Source Project: Awesome-WanAndroid   Author: JsonChao   File: EspressoIdlingResource.java    License: Apache License 2.0 4 votes vote down vote up
public static IdlingResource getIdlingResource() {
    return mCountingIdlingResource;
}
 
Example #17
Source Project: android-espresso-revealed   Author: Apress   File: TasksActivity.java    License: Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public IdlingResource getCountingIdlingResource() {
    return EspressoIdlingResource.getIdlingResource();
}
 
Example #18
Source Project: android-espresso-revealed   Author: Apress   File: AddEditTaskActivity.java    License: Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public IdlingResource getCountingIdlingResource() {
    return EspressoIdlingResource.getIdlingResource();
}
 
Example #19
Source Project: android-espresso-revealed   Author: Apress   File: EspressoIdlingResource.java    License: Apache License 2.0 4 votes vote down vote up
public static IdlingResource getIdlingResource() {
    return mCountingIdlingResource;
}
 
Example #20
Source Project: flowless   Author: Zhuinden   File: EspressoIdlingResource.java    License: Apache License 2.0 4 votes vote down vote up
public static IdlingResource getIdlingResource() {
    return mCountingIdlingResource;
}
 
Example #21
Source Project: mangosta-android   Author: esl   File: MainMenuActivityInstrumentedTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void initializeOneToOneChatsList() throws Exception {
    launchActivity();

    assumeTrue(isUserLoggedIn());

    IdlingResource resource = startTiming(5000);

    // Obtain the one to one chats fragment
    ChatsListsFragment chatsListsFragment = getChatsListFragment();

    // Check if it loads the correct amount of chats
    assertEquals(getOneToOneChatsCount(chatsListsFragment), mOneToOneChats.size());

    checkOneToOneChatsRecyclerViewContent(mOneToOneChatNames);

    stopTiming(resource);
}
 
Example #22
Source Project: mangosta-android   Author: esl   File: MainMenuActivityInstrumentedTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void initializeMUCLightList() throws Exception {
    launchActivity();

    assumeTrue(isUserLoggedIn());

    IdlingResource resource = startTiming(5000);

    // Obtain the one to one chats fragment
    ChatsListsFragment chatsListsFragment = getChatsListFragment();

    // Check if it loads the correct amount of chats
    assertEquals(getGroupChatsCount(chatsListsFragment), mMUCLights.size());

    checkGroupChatsRecyclerViewContent(mMUCLightNames);

    stopTiming(resource);
}
 
Example #23
Source Project: mangosta-android   Author: esl   File: CreateBlogActivityInstrumentedTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void createBlogPost() throws Exception {
    assumeTrue(isUserLoggedIn());

    int blogPostsCount = getBlogPostsCount();

    mActivity.startActivity(new Intent(mActivity, CreateBlogActivity.class));

    onView(withId(R.id.createBlogFloatingButton))
            .check(matches(isDisplayed()))
            .check(matches(isClickable()))
            .perform(click());

    // nothing happens because the content is empty

    String newBlogPostContent = "Blog post test";

    // now I complete the content
    onView(withId(R.id.createBlogText))
            .check(matches(isDisplayed()))
            .check(matches(isFocusable()))
            .perform(typeText(newBlogPostContent))
            .check(matches(hasFocus()))
            .check(matches(withText(newBlogPostContent)));

    // save it in mock
    addBlogPostToMockResponse(newBlogPostContent);

    // create blog post
    onView(withId(R.id.createBlogFloatingButton))
            .check(matches(isDisplayed()))
            .check(matches(isClickable()))
            .perform(click());

    IdlingResource resource = startTiming(2000);

    onView(withId(R.id.blogsRecyclerView))
            .check(matches(isDisplayed()));

    assertEquals(blogPostsCount + 1, getBlogPostsCount());

    stopTiming(resource);
}
 
Example #24
Source Project: mangosta-android   Author: esl   File: BaseInstrumentedTest.java    License: Apache License 2.0 4 votes vote down vote up
protected IdlingResource startTiming(long time) {
    IdlingResource idlingResource = new ElapsedTimeIdlingResource(time);
    Espresso.registerIdlingResources(idlingResource);
    return idlingResource;
}
 
Example #25
Source Project: mangosta-android   Author: esl   File: BaseInstrumentedTest.java    License: Apache License 2.0 4 votes vote down vote up
protected void stopTiming(IdlingResource idlingResource) {
    Espresso.unregisterIdlingResources(idlingResource);
}
 
Example #26
Source Project: KataSuperHeroesAndroid   Author: Karumi   File: SuperHeroDetailActivityTests.java    License: Apache License 2.0 4 votes vote down vote up
@After public void tearDown() {
  List<IdlingResource> idlingResources = getIdlingResources();
  for (IdlingResource resource : idlingResources) {
    unregisterIdlingResources(resource);
  }
}
 
Example #27
Source Project: AndroidProjects   Author: why168   File: EspressoIdlingResource.java    License: MIT License 4 votes vote down vote up
public static IdlingResource getIdlingResource() {
    return mCountingIdlingResource;
}
 
Example #28
Source Project: AndroidProjects   Author: why168   File: AddEditTaskActivity.java    License: MIT License 4 votes vote down vote up
@VisibleForTesting
public IdlingResource getCountingIdlingResource() {
    return EspressoIdlingResource.getIdlingResource();
}
 
Example #29
Source Project: AndroidProjects   Author: why168   File: TasksActivity.java    License: MIT License 4 votes vote down vote up
@VisibleForTesting
public IdlingResource getCountingIdlingResource() {
    return EspressoIdlingResource.getIdlingResource();
}
 
Example #30
Source Project: okhttp-idling-resource   Author: JakeWharton   File: OkHttp3IdlingResourceTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void name() {
  OkHttpClient client = new OkHttpClient();
  IdlingResource idlingResource = OkHttp3IdlingResource.create("Ok!", client);
  assertThat(idlingResource.getName()).isEqualTo("Ok!");
}