當前位置: 首頁>>代碼示例>>Java>>正文


Java PerformException類代碼示例

本文整理匯總了Java中android.support.test.espresso.PerformException的典型用法代碼示例。如果您正苦於以下問題:Java PerformException類的具體用法?Java PerformException怎麽用?Java PerformException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PerformException類屬於android.support.test.espresso包,在下文中一共展示了PerformException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: perform

import android.support.test.espresso.PerformException; //導入依賴的package包/類
public void perform(UiController uiController, View view) {
    RecyclerView recyclerView = (RecyclerView) view;
    (new ScrollToPositionViewAction(this.position)).perform(uiController, view);
    uiController.loopMainThreadUntilIdle();

    View targetView = recyclerView.getChildAt(this.position).findViewById(this.viewId);

    if (targetView == null) {
        throw (new PerformException.Builder()).withActionDescription(this.toString())
                .withViewDescription(HumanReadables.describe(view))
                .withCause(new IllegalStateException(
                        "No view with id "
                                + this.viewId
                                + " found at position: "
                                + this.position)
                )
                .build();
    }
    else {
        this.viewAction.perform(uiController, targetView);
    }
}
 
開發者ID:graviton57,項目名稱:DOUSalaries,代碼行數:23,代碼來源:TestUtils.java

示例2: perform

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Override
public void perform(UiController uiController, View view) {
    if (isDisplayingAtLeast(90).matches(view)) {
        Log.i(TAG, "View is already displayed. Returning.");
        return;
    }
    Rect rect = new Rect();
    view.getDrawingRect(rect);
    if (!view.requestRectangleOnScreen(rect, true /* immediate */)) {
        Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled.");
    }
    uiController.loopMainThreadUntilIdle();
    if (!isDisplayingAtLeast(90).matches(view)) {
        throw new PerformException.Builder()
                .withActionDescription(this.getDescription())
                .withViewDescription(HumanReadables.describe(view))
                .withCause(new RuntimeException(
                        "Scrolling to view was attempted, but the view is not displayed"))
                .build();
    }
}
 
開發者ID:st1hy,項目名稱:Red-Calorie,代碼行數:22,代碼來源:NestedScrollToAction.java

示例3: perform

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Override
public void perform(UiController uiController, View view) {
  if (isDisplayingAtLeast(90).matches(view)) {
    Log.i(TAG, "View is already displayed. Returning.");
    return;
  }
  Rect rect = new Rect();
  view.getDrawingRect(rect);
  if (!view.requestRectangleOnScreen(rect, true /* immediate */)) {
    Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled.");
  }
  uiController.loopMainThreadUntilIdle();
  if (!isDisplayingAtLeast(90).matches(view)) {
    throw new PerformException.Builder()
        .withActionDescription(this.getDescription())
        .withViewDescription(HumanReadables.describe(view))
        .withCause(new RuntimeException("Scrolling to view was attempted, but the view is not displayed"))
        .build();
  }
}
 
開發者ID:xmartlabs,項目名稱:bigbang,代碼行數:21,代碼來源:ScrollToActionForNestedScrollView.java

示例4: getUserFriendlyError

import android.support.test.espresso.PerformException; //導入依賴的package包/類
/**
 * When the error is coming from espresso, it is more user friendly to:
 * 1. propagate assertions as assertions
 * 2. swap the stack trace of the error to that of current thread (which will show
 * directly where the actual problem is)
 */
private Throwable getUserFriendlyError(Throwable error, Matcher<View> viewMatcher, String screenShotLocation) {
    String formattedScreenLocation = "";
    if (screenShotLocation != null) {
        formattedScreenLocation = " \n. Location of Screenshot:  \n " + screenShotLocation;
    }
    if (error instanceof PerformException) {
        // Re-throw the exception with the viewMatcher (used to locate the view) as the view
        // description (makes the error more readable). The reason we do this here: not all creators
        // of PerformException have access to the viewMatcher.
        throw new PerformException.Builder()
                .from((PerformException) error)
                .withViewDescription(viewMatcher.toString() + formattedScreenLocation)
                .build();
    }

    if (error instanceof AssertionError) {
        // reports Failure instead of Error.
        // assertThat(...) throws an AssertionFailedError.
        error = new AssertionFailedWithCauseError(error.getMessage() + formattedScreenLocation, error);
    }

    error.setStackTrace(Thread.currentThread().getStackTrace());
    return error;
}
 
開發者ID:yrizk,項目名稱:Espresso-CustomFailureHandler,代碼行數:31,代碼來源:ScreenShotFailureHandler.java

示例5: perform

import android.support.test.espresso.PerformException; //導入依賴的package包/類
public void perform(UiController uiController, View view) {
    RecyclerView recyclerView = (RecyclerView) view;
    (new ScrollToPositionViewAction(this.position)).perform(uiController, view);
    uiController.loopMainThreadUntilIdle();

    View targetView = recyclerView.getChildAt(this.position).findViewById(this.viewId);

    if (targetView == null) {
        throw (new PerformException.Builder()).withActionDescription(this.toString())
                .withViewDescription(

                        HumanReadables.describe(view))
                .withCause(new IllegalStateException(
                        "No view with id "
                                + this.viewId
                                + " found at position: "
                                + this.position))
                .build();
    } else {
        this.viewAction.perform(uiController, targetView);
    }
}
 
開發者ID:52inc,項目名稱:Scoops,代碼行數:23,代碼來源:TestUtils.java

示例6: checkView

import android.support.test.espresso.PerformException; //導入依賴的package包/類
public RecyclerViewInteraction checkView(final @IdRes int id, final ViewAssertion itemViewAssertion) {
    viewInteraction.check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException ex) {
            RecyclerView recyclerView = (RecyclerView) view;
            RecyclerView.ViewHolder viewHolderForPosition = recyclerView.findViewHolderForLayoutPosition(position);
            if (viewHolderForPosition == null) {
                throw (new PerformException.Builder())
                        .withActionDescription(toString())
                        .withViewDescription(HumanReadables.describe(view))
                        .withCause(new IllegalStateException("No view holder at position: " + position))
                        .build();
            } else {
                View viewAtPosition = viewHolderForPosition.itemView.findViewById(id);
                itemViewAssertion.check(viewAtPosition, ex);
            }
        }
    });
    return this;
}
 
開發者ID:sewerk,項目名稱:Bill-Calculator,代碼行數:21,代碼來源:RecyclerViewInteraction.java

示例7: perform

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Override
public final void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();

    long finishTime = System.currentTimeMillis() + duration;
    while (System.currentTimeMillis() < finishTime) {
        if (isConditionMet(view)) {
            return;
        }
        uiController.loopMainThreadForAtLeast(50L);
    }

    throw new PerformException.Builder()
            .withActionDescription(this.getDescription())
            .withViewDescription(HumanReadables.describe(view))
            .withCause(new TimeoutException())
            .build();
}
 
開發者ID:yandex-money,項目名稱:yandex-money-sdk-android,代碼行數:19,代碼來源:MoreViewActions.java

示例8: performWildCardAction

import android.support.test.espresso.PerformException; //導入依賴的package包/類
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;

    }
 
開發者ID:cuplv,項目名稱:ChimpCheck,代碼行數:37,代碼來源:Performer.java

示例9: check

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Override
public final void check(View view, NoMatchingViewException e) {
    RecyclerView recyclerView = (RecyclerView) view;
    RecyclerView.ViewHolder viewHolderForPosition = recyclerView.findViewHolderForLayoutPosition(position);
    if (viewHolderForPosition == null) {
        throw (new PerformException.Builder())
                .withActionDescription(toString())
                .withViewDescription(HumanReadables.describe(view))
                .withCause(new IllegalStateException("No view holder at position: " + position))
                .build();
    } else {
        View viewAtPosition = viewHolderForPosition.itemView;
        itemViewAssertion.check(item, viewAtPosition, e);
    }
}
 
開發者ID:igrow-systems,項目名稱:igrow-android,代碼行數:16,代碼來源:RecyclerItemViewAssertion.java

示例10: perform

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Override
public void perform(UiController uiController, View view) {
  ViewMatcherIdlingResource idlingResource = new ViewMatcherIdlingResource(timeout, viewMatcher, view);
  registerIdlingResources(idlingResource);
  uiController.loopMainThreadUntilIdle();
  unregisterIdlingResources(idlingResource);
  if(!idlingResource.isMatched()) {
    throw new PerformException.Builder()
      .withActionDescription(getDescription())
      .withViewDescription(HumanReadables.getViewHierarchyErrorMessage(view, null, "Action timed out : " + getDescription(), null))
      .build();
  }
}
 
開發者ID:jainsahab,項目名稱:AndroidSnooper,代碼行數:14,代碼來源:WaitForViewAction.java

示例11: waitForMatch

import android.support.test.espresso.PerformException; //導入依賴的package包/類
public static ViewAction waitForMatch(final Matcher<View> aViewMatcher, final long timeout) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {
            return "Waiting for view matching " + aViewMatcher;
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();

            final long startTime = System.currentTimeMillis();
            final long endTime = startTime + timeout;

            do {
                for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
                    if (aViewMatcher.matches(child)) {
                        // found
                        return;
                    }
                }


                uiController.loopMainThreadForAtLeast(50);
            } while (System.currentTimeMillis() < endTime);

            //The action has timed out.
            throw new PerformException.Builder()
                    .withActionDescription(getDescription())
                    .withViewDescription("")
                    .withCause(new TimeoutException())
                    .build();
        }
    };
}
 
開發者ID:IrrilevantHappyLlamas,項目名稱:Runnest,代碼行數:41,代碼來源:EspressoTest.java

示例12: check

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Override
public final void check(View view, NoMatchingViewException e) {
  RecyclerView recyclerView = (RecyclerView) view;
  RecyclerView.ViewHolder viewHolderForPosition =
      recyclerView.findViewHolderForLayoutPosition(position);
  if (viewHolderForPosition == null) {
    throw (new PerformException.Builder()).withActionDescription(toString())
        .withViewDescription(HumanReadables.describe(view))
        .withCause(new IllegalStateException("No view holder at position: " + position))
        .build();
  } else {
    View viewAtPosition = viewHolderForPosition.itemView;
    itemViewAssertion.check(item, viewAtPosition, e);
  }
}
 
開發者ID:pabloserranof,項目名稱:GuardianReader,代碼行數:16,代碼來源:RecyclerItemViewAssertion.java

示例13: testFaultyClickArgumentsView

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Test
public void testFaultyClickArgumentsView() {
    expectedException.expect(PerformException.class);
    expectedException.expectCause(allOf(
            isA(SporkRuntimeException.class),
            hasMessage(containsString("onClick() failed because the method arguments are invalid"))
    ));

    TestFaultyClickArgumentsView view = activityRule.getActivity().getTestFaultyClickArgumentsView();

    assertNotNull(view);
    onView(withId(view.getId())).perform(click());
}
 
開發者ID:ByteWelder,項目名稱:Spork,代碼行數:14,代碼來源:ClickBindingTest.java

示例14: perform

import android.support.test.espresso.PerformException; //導入依賴的package包/類
@Override
public void perform(UiController uiController, View view) {
    if (isDisplayingAtLeast(90).matches(view)) {
        Log.i(TAG, "View is already displayed. Returning.");
        return;
    }

    View parentScrollView = findScrollView(view);

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parentScrollView.getLayoutParams();
    params.setBehavior(null);
    parentScrollView.requestLayout();

    uiController.loopMainThreadUntilIdle();

    Rect rect = new Rect();
    view.getDrawingRect(rect);
    if (!view.requestRectangleOnScreen(rect, true /* immediate */)) {
        Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled.");
    }

    uiController.loopMainThreadUntilIdle();

    if (!isDisplayingAtLeast(90).matches(view)) {
        throw new PerformException.Builder()
                .withActionDescription(this.getDescription())
                .withViewDescription(HumanReadables.describe(view))
                .withCause(new RuntimeException(
                        "Scrolling to view was attempted, but the view is not displayed"))
                .build();
    }
}
 
開發者ID:mercadopago,項目名稱:px-android,代碼行數:33,代碼來源:NestedScrollViewScrollToAction.java

示例15: findScrollView

import android.support.test.espresso.PerformException; //導入依賴的package包/類
private View findScrollView(View view) {
    View parent = (View) view.getParent();
    if (parent != null) {
        if (parent instanceof NestedScrollView) {
            return parent;
        }
        return findScrollView(parent);
    }
    throw new PerformException.Builder()
            .withActionDescription(this.getDescription())
            .withViewDescription(HumanReadables.describe(view))
            .withCause(new RuntimeException(
                    "Scrolling aborted due to not being NestedScrollView child"))
            .build();
}
 
開發者ID:mercadopago,項目名稱:px-android,代碼行數:16,代碼來源:NestedScrollViewScrollToAction.java


注:本文中的android.support.test.espresso.PerformException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。