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

项目:ChimpCheck    文件:ClickPerformer.java   
@Override
public AppEventOuterClass.Click performMatcherAction(AppEventOuterClass.Click origin, Matcher<View> matcher) {
    if(origin.getUiid().getNameid().equals("ALLOW PERMISSION")){
        PermissionGranter.allowPermissionsIfNeeded();
        return origin;
    }
    try{
        AmbiguousCounter.resetCounter();
        Espresso.onView(new AmbiguousCounter(allOf(matcher, isDisplayed()))).perform(click());
    } catch (AmbiguousViewMatcherException avme) {
        avme.printStackTrace();
        int counter = AmbiguousCounter.getCounter();
        AmbiguousCounter.resetCounter();
        Random seed = new Random(System.currentTimeMillis());
        int randIdx = seed.nextInt(counter);
        Espresso.onView(MatchWithIndex.withIndex(matcher, randIdx)).perform(click());
    }

    return origin;
}
项目:ChimpCheck    文件:Performer.java   
public Act performWildCardAction(Act origin) {

        Espresso.onView(isRoot()).perform( new ChimpStagingAction() );

        chimpDriver.preemptiveTraceReport();

        try {
            ArrayList<UiObject2> uiObject2s = wildCardManager.retrieveUiObject2s(wildCardSelector, wildCardChildSelector, 10);
            ArrayList<WildCardTarget> matchers = MatcherManager.getViewMatchers(uiObject2s, userDefinedMatcher);

            while(matchers.size() > 0) {
                Log.i(tag("wildcard"), Integer.toString(matchers.size()));
                WildCardTarget target = wildCardManager.popOne(matchers);
                try {
                    Log.i(tag("wildcard"), "Attempting to perform action on UiObject");
                    Act result = performWildCardTargetAction(origin, target);
                    return result;
                } catch (AmbiguousViewMatcherException avme){
                    Log.e(tag("wildcard"), avme.toString());
                } catch (NoMatchingViewException nmve){
                    Log.e(tag("wildcard"), nmve.toString());
                } catch (PerformException pe){
                    Log.e(tag("wildcard"), pe.toString());

                }
            }

        } catch (Exception ee) {
            Log.e(tag("wildcard"), "Error occurred at wild card top-level");
            ee.printStackTrace();
        }

        Log.e(tag("wildcard"), "Exhausted all wild card options.");
        return null;

    }
项目: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()));
}
项目:malariapp    文件: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()));
}
项目:Ironhide    文件:ActivityViewFinder.java   
/** {@inheritDoc} */
@Override
public View getView() throws AmbiguousViewMatcherException, NoMatchingViewException {
    checkMainThread();
    final Predicate<View> matcherPredicate = new MatcherPredicateAdapter<>(
            checkNotNull(viewMatcher));
    Iterator<View> matchedViewIterator = Iterables.filter(
            breadthFirstViewTraversal(root),
            matcherPredicate).iterator();
    View matchedView = null;

    while (matchedViewIterator.hasNext()) {
        if (matchedView != null) {
            // Ambiguous!
            throw new AmbiguousViewMatcherException.Builder()
                    .includeViewHierarchy(false)
                    .withViewMatcher(viewMatcher)
                    .withRootView(root)
                    .withView1(matchedView)
                    .withView2(matchedViewIterator.next())
                    .withOtherAmbiguousViews(Iterators.toArray(matchedViewIterator, View.class))
                    .build();
        }
        else
            matchedView = matchedViewIterator.next();
    }

    // no need to throw NoMatchingViewExceptions. We want the null value if view does not exist
    return matchedView;
}