Java 类android.support.test.espresso.IdlingResource 实例源码

项目:android-architecture-components    文件:TaskExecutorWithIdlingResourceRule.java   
@Override
protected void starting(Description description) {
    Espresso.registerIdlingResources(new IdlingResource() {
        @Override
        public String getName() {
            return "architecture components idling resource";
        }

        @Override
        public boolean isIdleNow() {
            return TaskExecutorWithIdlingResourceRule.this.isIdle();
        }

        @Override
        public void registerIdleTransitionCallback(ResourceCallback callback) {
            callbacks.add(callback);
        }
    });
    super.starting(description);
}
项目:RxIdler    文件:DelegatingIdlingResourceSchedulerTest.java   
@Before public void setUp() {
  scheduler.registerIdleTransitionCallback(new IdlingResource.ResourceCallback() {
    @Override public void onTransitionToIdle() {
      idleCount.incrementAndGet();
    }
  });
}
项目:Android-CleanArchitecture-Java    文件:TaskExecutorWithIdlingResourceRule.java   
@Override
protected void starting(Description description) {
    Espresso.registerIdlingResources(new IdlingResource() {
        @Override
        public String getName() {
            return "architecture components idling resource";
        }

        @Override
        public boolean isIdleNow() {
            return TaskExecutorWithIdlingResourceRule.this.isIdle();
        }

        @Override
        public void registerIdleTransitionCallback(ResourceCallback callback) {
            callbacks.add(callback);
        }
    });
    super.starting(description);
}
项目:mangosta-android    文件:LoginInstrumentedTest.java   
@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);
}
项目:AndroidTesting    文件:TimingActivityTest.java   
private static void waitFor(long waitingTime, boolean success) {
    //Start
    onView(withId(R.id.toggle_button))
            .check(matches(withText(R.string.start)))
            .perform(click());

    //Mack sure Espresso does not time out
    IdlingPolicies.setMasterPolicyTimeout(waitingTime * 2, TimeUnit.MILLISECONDS);
    IdlingPolicies.setIdlingResourceTimeout(waitingTime * 2, TimeUnit.MILLISECONDS);

    //Now we wait
    IdlingResource idlingResource = new ElapsedTimeIdlingResource(waitingTime);
    Espresso.registerIdlingResources(idlingResource);

    //Stop and verify
    onView(withId(R.id.toggle_button))
            .check(matches(withText(R.string.stop)))
            .perform(click());
    onView(withId(R.id.result))
            .check(matches(withText(success ? R.string.success : R.string.failure)));

    //Clean up
    Espresso.unregisterIdlingResources(idlingResource);
}
项目:okhttp-idling-resource    文件:OkHttp3IdlingResourceTest.java   
@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);
}
项目:EDSApp    文件:PushConflictTest.java   
public static void checkConflict() {
    //when: click on assess tab + plus button
    onView(withTagValue(Matchers.is((Object) PreferencesState.getInstance().getContext().getString(R.string.tab_tag_improve)))).perform(click());


    IdlingResource idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);
    String text=getActivityInstance().getApplicationContext().getString(R.string.feedback_info_conflict);
    text=text.toUpperCase();
    onView(withText(text)).perform(click());

    Espresso.unregisterIdlingResources(idlingResource);

    //Wait for SurveyService loads feedback
    idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);
    try {
        onView(withId(R.string.feedback_info_conflict)).perform(click());
    }catch (Exception e){
        //It can fail if the mobile resolution fill the text
    }

    Espresso.unregisterIdlingResources(idlingResource);

}
项目:EDSApp    文件:SDKTestUtils.java   
public static void fillCompulsorySurvey(int numQuestions, String optionValue) {
    //when: answer NO to every question
    //Wait for fragment load data from SurveyService
    IdlingResource idlingResource=null;
    onView(withTagValue(Matchers.is((Object) getActivityInstance().getApplicationContext().getString(R.string.tab_tag_assess)))).perform(click());
    for (int i = 0; i < numQuestions; i++) {
        try {
            idlingResource = new ElapsedTimeIdlingResource(1 * 1000);
            Espresso.registerIdlingResources(idlingResource);
            onData(is(instanceOf(Question.class)))
                    .inAdapterView(withId(R.id.listView))
                    .atPosition(i)
                    .onChildView(withId(R.id.answer)).onChildView(withText(optionValue))
                    .perform(click());
        } catch (NoMatchingViewException e) {
            Log.e(TAG,"Exception selecting option value " + optionValue);
        }
        finally {
            Espresso.unregisterIdlingResources(idlingResource);
        }
    }
}
项目:EDSApp    文件:SDKTestUtils.java   
public static Long markCompleteAndGoImprove() {
    Long idSurvey = getSurveyId();

    //when: Mark as completed
    onView(withId(R.id.score)).perform(click());
    onView(withText(MARK_AS_COMPLETED)).perform(click());
    onView(withText(android.R.string.ok)).perform(click());

    IdlingResource idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);

    onView(withTagValue(Matchers.is((Object) getActivityInstance().getApplicationContext().getString(R.string.tab_tag_improve)))).perform(click());

    Espresso.unregisterIdlingResources(idlingResource);
    return idSurvey;
}
项目:malariapp    文件:PushConflictTest.java   
public static void checkConflict() {
    //when: click on assess tab + plus button
    onView(withTagValue(Matchers.is((Object) PreferencesState.getInstance().getContext().getString(R.string.tab_tag_improve)))).perform(click());


    IdlingResource idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);
    String text=getActivityInstance().getApplicationContext().getString(R.string.feedback_info_conflict);
    text=text.toUpperCase();
    onView(withText(text)).perform(click());

    Espresso.unregisterIdlingResources(idlingResource);

    //Wait for SurveyService loads feedback
    idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);
    try {
        onView(withId(R.string.feedback_info_conflict)).perform(click());
    }catch (Exception e){
        //It can fail if the mobile resolution fill the text
    }

    Espresso.unregisterIdlingResources(idlingResource);

}
项目:malariapp    文件:SDKTestUtils.java   
public static void fillCompulsorySurvey(int numQuestions, String optionValue) {
    //when: answer NO to every question
    //Wait for fragment load data from SurveyService
    IdlingResource idlingResource=null;
    onView(withTagValue(Matchers.is((Object) getActivityInstance().getApplicationContext().getString(R.string.tab_tag_assess)))).perform(click());
    for (int i = 0; i < numQuestions; i++) {
        try {
            idlingResource = new ElapsedTimeIdlingResource(1 * 1000);
            Espresso.registerIdlingResources(idlingResource);
            onData(is(instanceOf(Question.class)))
                    .inAdapterView(withId(R.id.listView))
                    .atPosition(i)
                    .onChildView(withId(R.id.answer)).onChildView(withText(optionValue))
                    .perform(click());
        } catch (NoMatchingViewException e) {
            Log.e(TAG,"Exception selecting option value " + optionValue);
        }
        finally {
            Espresso.unregisterIdlingResources(idlingResource);
        }
    }
}
项目:malariapp    文件:SDKTestUtils.java   
public static Long markCompleteAndGoImprove() {
    Long idSurvey = getSurveyId();

    //when: Mark as completed
    onView(withId(R.id.score)).perform(click());
    onView(withText(MARK_AS_COMPLETED)).perform(click());
    onView(withText(android.R.string.ok)).perform(click());

    IdlingResource idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);

    onView(withTagValue(Matchers.is((Object) getActivityInstance().getApplicationContext().getString(R.string.tab_tag_improve)))).perform(click());

    Espresso.unregisterIdlingResources(idlingResource);
    return idSurvey;
}
项目:espresso-samples    文件:MainActivityTest.java   
private static void waitFor(long waitingTime, boolean success) {
  // Start
  onView(withId(R.id.toggle_button))
      .check(matches(withText(R.string.start)))
      .perform(click());

  // Make sure Espresso does not time out
  IdlingPolicies.setMasterPolicyTimeout(waitingTime * 2, TimeUnit.MILLISECONDS);
  IdlingPolicies.setIdlingResourceTimeout(waitingTime * 2, TimeUnit.MILLISECONDS);

  // Now we wait
  IdlingResource idlingResource = new ElapsedTimeIdlingResource(waitingTime);
  IdlingRegistry.getInstance().register(idlingResource);

  // Stop and verify
  onView(withId(R.id.toggle_button))
      .check(matches(withText(R.string.stop)))
      .perform(click());
  onView(withId(R.id.result))
      .check(matches(withText(success ? R.string.success: R.string.failure)));

  // Clean up
  IdlingRegistry.getInstance().unregister(idlingResource);
}
项目:BuddyBook    文件:MainActivity.java   
/**
 * Only called from test, creates and returns a new {@link SimpleIdlingResource}.
 */
@VisibleForTesting
@NonNull
public IdlingResource getIdlingResource() {
    if (mIdlingResource == null) {
        mIdlingResource = new SimpleIdlingResource();
    }
    return mIdlingResource;
}
项目:SgPSI    文件:PsiListActivity.java   
@VisibleForTesting
@NonNull
public IdlingResource getIdlingResource() {
    if (idlingResource == null) {
        idlingResource = new RecipesIdlingResource();
    }
    return idlingResource;
}
项目:BakingApp    文件:MainActivityFragment.java   
@NonNull
public IdlingResource getIdlingResource(){
    if(mIdlingResource == null) {
        mIdlingResource = new SimpleIdlingResource();
    }
    return mIdlingResource;
}
项目:android-architecture-components    文件:TaskExecutorWithIdlingResourceRule.java   
@Override
protected void onIdle() {
    super.onIdle();
    for (IdlingResource.ResourceCallback callback : callbacks) {
        callback.onTransitionToIdle();
    }
}
项目:starwarsshop    文件:ElapsedTimeIdlingResource.java   
public static IdlingResource waitFor(long waitingTime) {

        // Make sure Espresso does not time out
        IdlingPolicies.setMasterPolicyTimeout(waitingTime * 2, TimeUnit.MILLISECONDS);
        IdlingPolicies.setIdlingResourceTimeout(waitingTime * 2, TimeUnit.MILLISECONDS);

        // Now we wait
        IdlingResource idlingResource = new ElapsedTimeIdlingResource(waitingTime);
        Espresso.registerIdlingResources(idlingResource);

        return idlingResource;
    }
项目:RxIdler    文件:DelegatingIdlingResourceSchedulerTest.java   
@Before public void setUp() {
  scheduler.registerIdleTransitionCallback(new IdlingResource.ResourceCallback() {
    @Override public void onTransitionToIdle() {
      idleCount.incrementAndGet();
    }
  });
}
项目:meat-grinder    文件:MainActivityTest.java   
@Test
public void testFabButtonAndList() {
    IdlingResource ir = new RecyclerViewScrollingIdlingResource((RecyclerView) activity.findViewById(R.id.list));
    IdlingRegistry.getInstance().register(ir);
    Matcher listMatcher = withId(R.id.list);
    onView(listMatcher).perform(smoothScrollTo(12));
    onView(withId(R.id.fab)).perform(click());
    onView(listMatcher).perform(smoothScrollTo(0));
    onView(withId(R.id.fab)).perform(click());
    IdlingRegistry.getInstance().unregister(ir);
}
项目:cat-is-a-dog    文件:LoginActivity.java   
/**
 * Only called from test, creates and returns a new {@link SimpleIdlingResource}.
 */
@VisibleForTesting
@NonNull
public IdlingResource getIdlingResource() {
    if (mIdlingResource == null) {
        mIdlingResource = new SimpleIdlingResource();
    }
    return mIdlingResource;
}
项目:Android-CleanArchitecture-Java    文件:TaskExecutorWithIdlingResourceRule.java   
@Override
protected void onIdle() {
    super.onIdle();
    for (IdlingResource.ResourceCallback callback : callbacks) {
        callback.onTransitionToIdle();
    }
}
项目:AndroidArchitecture    文件:LogInActivityTest.java   
private void checkActionForDialog(@NonNull Runnable runnable) {
    IdlingResource resource = TestUtils.waitForDialog(
            mActivityRule.getActivity().getFragmentManager(),
            LoadingDialog.class.getSimpleName());
    runnable.run();
    Espresso.unregisterIdlingResources(resource);
}
项目:AndroidArchitecture    文件:TestUtils.java   
@NonNull
public static IdlingResource waitForDialog(@NonNull FragmentManager fragmentManager, @NonNull String tag) {
    IdlingPolicies.setMasterPolicyTimeout(3, TimeUnit.SECONDS);
    IdlingPolicies.setIdlingResourceTimeout(3, TimeUnit.SECONDS);

    IdlingResource idlingResource = new DialogFragmentIdlingResource(fragmentManager, tag);
    Espresso.registerIdlingResources(idlingResource);

    return idlingResource;
}
项目:mangosta-android    文件:LoginInstrumentedTest.java   
@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);
}
项目:mangosta-android    文件:MainMenuInstrumentedTest.java   
@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);
}
项目:bigbang    文件:TestRunner.java   
@Override
public void callApplicationOnCreate(Application app) {
  super.callApplicationOnCreate(app);

  TestApplication testApp = (TestApplication) app;
  testApp.inject(this);

  IdlingResource picassoIdlingResource = OkHttp3IdlingResource.create(
      String.format(Locale.US, "%sOkHttp", OkHttpModule.CLIENT_PICASSO), picassoOkHttpClient);
  Espresso.registerIdlingResources(picassoIdlingResource);

  IdlingResource serviceIdlingResource = OkHttp3IdlingResource.create(
      String.format(Locale.US, "%sOkHttp", OkHttpModule.CLIENT_SERVICE), serviceOkHttpClient);
  Espresso.registerIdlingResources(serviceIdlingResource);
}
项目:audiolibros    文件:SplashActivityTest.java   
@Test
public void shouldOpenMainActivityAfterSplashTimeFinish() {
    mActivityTestRule.launchActivity(new Intent());
    IdlingResource idlingResource = new ElapsedTimeIdlingResource(HACK_WATTING_TIME);
    Espresso.registerIdlingResources(idlingResource);

    intended(hasComponent(MainActivity.class.getCanonicalName()));
    Espresso.unregisterIdlingResources(idlingResource);
}
项目:apollo-android    文件:ApolloIdlingResourceTest.java   
@SuppressWarnings("CheckReturnValue")
@Test
public void checkIdlingResourceTransition_whenCallIsQueued() throws IOException, ApolloException {
  server.enqueue(mockResponse());

  apolloClient = ApolloClient.builder()
      .okHttpClient(okHttpClient)
      .dispatcher(new Executor() {
        @Override public void execute(Runnable command) {
          command.run();
        }
      })
      .serverUrl(server.url("/"))
      .build();

  final AtomicInteger counter = new AtomicInteger(1);
  idlingResource = ApolloIdlingResource.create(IDLING_RESOURCE_NAME, apolloClient);

  idlingResource.registerIdleTransitionCallback(new IdlingResource.ResourceCallback() {
    @Override public void onTransitionToIdle() {
      counter.decrementAndGet();
    }
  });

  assertThat(counter.get()).isEqualTo(1);
  Rx2Apollo.from(apolloClient.query(EMPTY_QUERY)).blockingFirst();
  assertThat(counter.get()).isEqualTo(0);
}
项目:PdfViewPager    文件:Sample2Tests.java   
@After
public void tearDown() {
    List<IdlingResource> idlingResources = Espresso.getIdlingResources();
    for (IdlingResource resource : idlingResources) {
        Espresso.unregisterIdlingResources(resource);
    }
}
项目: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);

}
项目:AndroidSchool    文件:AuthActivityTest.java   
@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);
}
项目:EDSApp    文件:SDKVariantUtils.java   
public static void selectSurvey(int idxOrgUnit, int idxProgram, int seconds) {
    //when: click on assess tab + plus button

    IdlingResource idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
    Espresso.registerIdlingResources(idlingResource);

    try {
        onView(withText(android.R.string.ok)).perform(click());
    }catch(NoMatchingViewException e){
        e.printStackTrace();
        Log.d(TAG, "the enduser licence was accepted.");
    }
    finally {
        Espresso.unregisterIdlingResources(idlingResource);
    }

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


    idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
    Espresso.registerIdlingResources(idlingResource);

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

    Espresso.unregisterIdlingResources(idlingResource);

    onData(is(instanceOf(OrgUnit.class))).atPosition(idxOrgUnit).perform(click());


    idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
    Espresso.registerIdlingResources(idlingResource);

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

    Espresso.unregisterIdlingResources(idlingResource);
    onData(is(instanceOf(Program.class))).atPosition(idxProgram).perform(click());
    onView(withText(R.string.create_info_ok)).perform(click());
}
项目:EDSApp    文件:SDKVariantUtils.java   
public static void fillSurvey(int numQuestions, String optionValue,int seconds) {
    //when: answer NO to every question
    //Wait for fragment load data from SurveyService
    IdlingResource idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
    Espresso.registerIdlingResources(idlingResource);

    onView(withTagValue(Matchers.is((Object) AssessModuleController.getSimpleName()))).perform(click());
    Espresso.unregisterIdlingResources(idlingResource);

    for (int i = 0; i < numQuestions; i++) {
        try {
            idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
            Espresso.registerIdlingResources(idlingResource);
            onData(is(instanceOf(Question.class)))
                    .inAdapterView(withId(R.id.listView))
                    .atPosition(i)
                    .onChildView(withId(R.id.answer)).onChildView(withText(optionValue))
                    .perform(click());
        } catch (NoMatchingViewException e) {
            Log.e(TAG,"Exception selecting option value " + optionValue);
        }
        finally{
            Espresso.unregisterIdlingResources(idlingResource);
        }

    }
    //then: back + confirm
    Espresso.pressBack();
    idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
    Espresso.registerIdlingResources(idlingResource);
    onView(withText(android.R.string.ok)).perform(click());
    Espresso.unregisterIdlingResources(idlingResource);
}
项目:EDSApp    文件:AssessCompulsoryTest.java   
@Test
public void assessCompulsoryComplete() {
    //GIVEN
    if(LoginActivity.class.equals(SDKTestUtils.getActivityInstance().getClass())) {
        login(HNQIS_DEV_CI, TEST_USERNAME_WITH_PERMISSION, TEST_PASSWORD_WITH_PERMISSION);
        waitForPull(DEFAULT_WAIT_FOR_PULL);
    }
    startSurvey(SDKTestUtils.TEST_FACILITY_1_IDX, SDKTestUtils.TEST_IMCI);
    fillCompulsorySurvey(13, "Yes");

    //WHEN
    Espresso.pressBack();
    //select continue later and go to assess
    onView(withText(R.string.dialog_continue_later_option)).perform(click());

    //THEN
    onView(withText(R.string.dashboard_info_ready_to_upload)).check(matches(isDisplayed()));


    //WHEN
    Long idSurvey = SDKTestUtils.editSurvey();
    IdlingResource idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);
    Espresso.pressBack();
    Espresso.unregisterIdlingResources(idlingResource);
    //select complete survey on exit
    onView(withText(R.string.dialog_complete_option)).perform(click());
    //confirm(are you sure?)
    onView(withText(android.R.string.yes)).perform(click());
    //info dialog
    onView(withText(android.R.string.ok)).perform(click());

    //THEN
    //then: Survey is pushed (UID)
    Log.d(TAG, "Session user ->" + Session.getUser());
    Survey survey = waitForPush(SDKTestUtils.DEFAULT_WAIT_FOR_PUSH, idSurvey);
    assertTrue(survey.isCompleted() || survey.isSent());
}
项目:EDSApp    文件:AssessCompleteToFeedbackTest.java   
@Test
public void assessCompleteAndGoFeedback(){
    //GIVEN
    login(HNQIS_DEV_CI, TEST_USERNAME_WITH_PERMISSION, TEST_PASSWORD_WITH_PERMISSION);
    waitForPull(DEFAULT_WAIT_FOR_PULL);
    startSurvey(SDKTestUtils.TEST_FACILITY_1_IDX, SDKTestUtils.TEST_FAMILY_PLANNING_IDX);
    //randomResponseNumber is used to randomize the survey answers to obtain a different main score between tests.
    int randomResponseNumber=2 + (int)(Math.random() * 7);
    fillSurvey(randomResponseNumber, "Yes");

    //WHEN
    Long idSurvey=SDKTestUtils.markCompleteAndGoFeedback();
    Survey survey = Survey.findById(idSurvey);


    //THEN
    //check if is in feedback
    onView(withText(R.string.quality_of_care)).check(matches(isDisplayed()));
    onView(withText(String.format("%.1f%%", survey.getMainScore()))).check(matches(isDisplayed()));

    //WHEN
    onView(withText(R.string.feedback_return)).perform(click());

    //THEN

    IdlingResource idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
    Espresso.registerIdlingResources(idlingResource);
    try {
        onView(withText(String.format("%.1f %%", survey.getMainScore()))).check(matches(isDisplayed()));
    }catch(AmbiguousViewMatcherException e){
        Log.d(TAG,"Multiple surveys have the same score "+String.format("%.1f %%", survey.getMainScore()));
    }
    Espresso.unregisterIdlingResources(idlingResource);
    if(survey.isCompleted())
        onView(withText( "* "  + survey.getProgram().getName())).check(matches(isDisplayed()));
    else
        onView(withText("- "   + survey.getProgram().getName())).check(matches(isDisplayed()));
}
项目:EDSApp    文件:PushOKTest.java   
@Test
public void pushWithPermissionsDoesPush(){
    login(HNQIS_DEV_CI, TEST_USERNAME_WITH_PERMISSION, TEST_PASSWORD_WITH_PERMISSION);
    waitForPull(DEFAULT_WAIT_FOR_PULL);
    startSurvey(SDKTestUtils.TEST_FACILITY_1_IDX, SDKTestUtils.TEST_FAMILY_PLANNING_IDX);
    long numberOfEvents = 1;
    long eventCount = EventExtended.count();
    fillSurvey(7, "No");
    Long idSurvey=markInProgressAsCompleted();

    //then: Survey is pushed (UID)
    Log.d(TAG, "Session user ->"+ Session.getUser());
    Survey survey=waitForPush(SDKTestUtils.DEFAULT_WAIT_FOR_PUSH*1000,idSurvey);



    IdlingResource idlingResource = new ElapsedTimeIdlingResource(SDKTestUtils.DEFAULT_WAIT_FOR_PUSH *1000);
    Espresso.registerIdlingResources(idlingResource);
    Log.d(TAG,survey.toString());
    Espresso.unregisterIdlingResources(idlingResource);

    assertTrue(survey.getEventUid()!=null);

    assertTrue(numberOfEvents == EventExtended.count());
    assertTrue(eventCount +1 == EventExtended.count());

    //then: Row is gone
    onView(withId(R.id.score)).check(doesNotExist());
}
项目:EDSApp    文件:SDKTestUtils.java   
public static void waitForPull(int seconds) {
    //then: wait for progressactivity + dialog + ok (to move to dashboard)
    IdlingResource idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
    Espresso.registerIdlingResources(idlingResource);

    onView(withText(android.R.string.ok)).perform(click());

    Espresso.unregisterIdlingResources(idlingResource);
}
项目:EDSApp    文件:SDKTestUtils.java   
public static Survey waitForPush(int seconds, Long idSurvey) {
    //then: wait for pushservice

    IdlingResource idlingResource = new ElapsedTimeIdlingResource(seconds * 1000);
    Espresso.registerIdlingResources(idlingResource);

    Survey survey = Survey.findById(idSurvey);

    Espresso.unregisterIdlingResources(idlingResource);
    return survey;
}
项目:EDSApp    文件:SDKTestUtils.java   
public static void fillSurvey(int numQuestions, String optionValue) {
      //when: answer NO to every question
      //Wait for fragment load data from SurveyService
      IdlingResource idlingResource = new ElapsedTimeIdlingResource(5 * 1000);
      Espresso.registerIdlingResources(idlingResource);

      onView(withTagValue(Matchers.is((Object) AssessModuleController.getSimpleName()))).perform(click());
Espresso.unregisterIdlingResources(idlingResource);

      for (int i = 0; i < numQuestions; i++) {
          try {
              idlingResource = new ElapsedTimeIdlingResource(1 * 1000);
              Espresso.registerIdlingResources(idlingResource);
              onData(is(instanceOf(Question.class)))
                      .inAdapterView(withId(R.id.listView))
                      .atPosition(i)
                      .onChildView(withId(R.id.answer)).onChildView(withText(optionValue))
                      .perform(click());
          } catch (NoMatchingViewException e) {
              Log.e(TAG,"Exception selecting option value " + optionValue);
          }
          finally{
              Espresso.unregisterIdlingResources(idlingResource);
          }

      }
          //then: back + confirm
          Espresso.pressBack();
          idlingResource = new ElapsedTimeIdlingResource(1 * 1000);
          Espresso.registerIdlingResources(idlingResource);
          onView(withText(android.R.string.ok)).perform(click());
          Espresso.unregisterIdlingResources(idlingResource);
  }