Java Code Examples for android.support.test.espresso.AmbiguousViewMatcherException

The following are top voted examples for showing how to use android.support.test.espresso.AmbiguousViewMatcherException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ChimpCheck   File: ClickPerformer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 2
Project: ChimpCheck   File: Performer.java   View source code 5 votes vote down vote up
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;

    }
 
Example 3
Project: EDSApp   File: AssessCompleteToFeedbackTest.java   View source code 5 votes vote down vote up
@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()));
}
 
Example 4
Project: malariapp   File: AssessCompleteToFeedbackTest.java   View source code 5 votes vote down vote up
@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()));
}
 
Example 5
Project: Ironhide   File: ActivityViewFinder.java   View source code 5 votes vote down vote up
/** {@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;
}