本文整理匯總了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);
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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();
}
};
}
示例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);
}
}
示例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());
}
示例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();
}
}
示例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();
}