本文整理汇总了Java中android.support.test.espresso.ViewAssertion类的典型用法代码示例。如果您正苦于以下问题:Java ViewAssertion类的具体用法?Java ViewAssertion怎么用?Java ViewAssertion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ViewAssertion类属于android.support.test.espresso包,在下文中一共展示了ViewAssertion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchCityAndClick
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
@Test
public void searchCityAndClick() throws Exception {
List<Election> unfilteredList = electionActivity.getAdapter().getList();
onView(withId(R.id.search)).perform(click());
final Election toClick = unfilteredList.get(0);
onView(withId(android.support.design.R.id.search_src_text)).perform(typeText(toClick.getPlace()));
onView (withId (R.id.election_list)).check (ViewAssertions.matches (new Matchers().withListSize (1)));
onData(instanceOf(Election.class))
.inAdapterView(withId(R.id.election_list))
.atPosition(0)
.perform(click());
// intended(hasComponent(MainActivity.class.getName()));
onView(withId(R.id.app_bar)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
assertEquals(((Toolbar) view).getTitle(), toClick.getKind());
assertEquals(((Toolbar) view).getSubtitle(), toClick.getPlace());
}
});
}
示例2: hasHolderItem
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
@NonNull
public static ViewAssertion hasHolderItem(final Matcher<RecyclerView.ViewHolder> viewHolderMatcher) {
return new ViewAssertion() {
@Override public void check(View view, NoMatchingViewException e) {
if (!(view instanceof RecyclerView)) {
throw e;
}
boolean hasMatch = false;
RecyclerView rv = (RecyclerView) view;
for (int i = 0; i < rv.getChildCount(); i++) {
RecyclerView.ViewHolder vh = rv.findViewHolderForAdapterPosition(i);
hasMatch |= viewHolderMatcher.matches(vh);
}
Assert.assertTrue(hasMatch);
}
};
}
示例3: testAutoFocus
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
@Test
public void testAutoFocus() {
onView(withId(R.id.camera))
.check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
CameraView cameraView = (CameraView) view;
// This can fail on devices without auto-focus support
assertThat(cameraView.getAutoFocus(), is(true));
cameraView.setAutoFocus(false);
assertThat(cameraView.getAutoFocus(), is(false));
cameraView.setAutoFocus(true);
assertThat(cameraView.getAutoFocus(), is(true));
}
});
}
示例4: showingPreview
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
private static ViewAssertion showingPreview() {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (android.os.Build.VERSION.SDK_INT < 14) {
return;
}
CameraView cameraView = (CameraView) view;
TextureView textureView = (TextureView) cameraView.findViewById(R.id.texture_view);
Bitmap bitmap = textureView.getBitmap();
int topLeft = bitmap.getPixel(0, 0);
int center = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
int bottomRight = bitmap.getPixel(
bitmap.getWidth() - 1, bitmap.getHeight() - 1);
assertFalse("Preview possibly blank: " + Integer.toHexString(topLeft),
topLeft == center && center == bottomRight);
}
};
}
示例5: clickOnElection
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
@Test
public void clickOnElection() throws Exception {
final Election e = electionActivity.getAdapter().getItem(1);
onData(instanceOf(Election.class)) // We are using the position so don't need to specify a data matcher
.inAdapterView(withId(R.id.election_list)) // Specify the explicit id of the ListView
.atPosition(1) // Explicitly specify the adapter item to use
.perform(click());
// intended(hasComponent(MainActivity.class.getName()));
onView(withId(R.id.app_bar)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
assertEquals(((Toolbar) view).getTitle(), e.getKind());
assertEquals(((Toolbar) view).getSubtitle(), e.getPlace());
}
});
}
示例6: encrypt
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
private String encrypt(String text) throws InterruptedException {
final String[] result = new String[1];
onView(withId(R.id.editText4)).perform(scrollTo(), replaceText(text), closeSoftKeyboard());
onView(allOf(withId(R.id.button2), withText("Encrypt"))).perform(scrollTo(), click());
onView(withId(R.id.editText5)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
result[0] = String.valueOf(((EditText) view).getText());
}
});
onView(allOf(withId(R.id.button3), withText("Test Decrypt"))).perform(scrollTo(), click());
onView(withId(R.id.textView5)).check(matches(withText(text)));
onView(allOf(withId(R.id.button4), withText("Copy"))).perform(scrollTo(), click());
return result[0];
}
示例7: assertExist
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
/**
* Check that this item exist.
*
* Is true when adapter has matching item ignores the display state.
*
* @since Espresso Macchiato 0.6
*/
public void assertExist() {
findRecyclerView().check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (noViewFoundException != null) {
throw noViewFoundException;
}
RecyclerView recyclerView = (RecyclerView) view;
if (index >= recyclerView.getAdapter().getItemCount()) {
throw new AssertionFailedError("Requested item should exist.");
}
}
});
}
示例8: testAutoFocus
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
@Test
public void testAutoFocus() {
onView(withId(com.google.android.cameraview.test.R.id.camera))
.check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
CameraView cameraView = (CameraView) view;
// This can fail on devices without auto-focus support
assertThat(cameraView.getAutoFocus(), is(true));
cameraView.setAutoFocus(false);
assertThat(cameraView.getAutoFocus(), is(false));
cameraView.setAutoFocus(true);
assertThat(cameraView.getAutoFocus(), is(true));
}
});
}
示例9: showingPreview
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
private static ViewAssertion showingPreview() {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (android.os.Build.VERSION.SDK_INT < 14) {
return;
}
CameraView cameraView = (CameraView) view;
TextureView textureView = (TextureView) cameraView.findViewById(com.google.android.cameraview.test.R.id.texture_view);
Bitmap bitmap = textureView.getBitmap();
int topLeft = bitmap.getPixel(0, 0);
int center = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
int bottomRight = bitmap.getPixel(
bitmap.getWidth() - 1, bitmap.getHeight() - 1);
assertFalse("Preview possibly blank: " + Integer.toHexString(topLeft),
topLeft == center && center == bottomRight);
}
};
}
示例10: testTouchCoordinatorLayout
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
@Test
public void testTouchCoordinatorLayout() {
final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
down = false;
Espresso.onView(sameInstance((View) activity.mCoordinatorLayout))
.perform(ViewActions.click()) // Click outside the bottom sheet
.check(
new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
assertThat(e, is(nullValue()));
assertThat(view, is(notNullValue()));
// Check that the touch event fell through to the container
assertThat(down, is(true));
}
});
}
开发者ID:material-components,项目名称:material-components-android,代码行数:18,代码来源:BottomSheetBehaviorTouchTest.java
示例11: flexGridHasCode
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
public static ViewAssertion flexGridHasCode(final List<CodeLine> expectedCodeLines)
{
return new ViewAssertion()
{
@Override
public void check(View view, NoMatchingViewException noViewException)
{
FlexGrid flexGrid = (FlexGrid) view;
List<CodeLine> actualCodeLines = (List<CodeLine>) flexGrid.getItemsSource();
for (int i = 0; i < expectedCodeLines.size(); i++)
{
CodeLine expected = expectedCodeLines.get(i);
CodeLine actual = actualCodeLines.get(i);
assertEquals(expected.getCodeText(), actual.getCodeText());
}
}
};
}
示例12: checkMessagesOnlyFromToday
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
public static ViewAssertion checkMessagesOnlyFromToday() {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
if (!(view instanceof RecyclerView)) {
throw e;
}
RecyclerView rv = (RecyclerView) view;
RecyclerMessageAdapter recyclerMessageAdapter = (RecyclerMessageAdapter) rv.getAdapter();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("OfDate-" + (new Date()).toString() + " { ");
for (int index = 0; index < recyclerMessageAdapter.getItemCount(); index++) {
if (recyclerMessageAdapter.getItem(index) instanceof Message) {
Message message = (Message) recyclerMessageAdapter.getItem(index);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.US);
stringBuilder.append(message.getID() + "-" + sdf.format(message.getTimestamp()) + " , ");
assertTrue("This message is not of today ID=" + message.getID() + ":" + message.getIdForHolder() + "\ncontent=" + message.getContent(), DateUtils.isToday(message.getTimestamp().getTime()));
}
}
stringBuilder.append(" }");
printLogInPartsIfExceeded(stringBuilder, "checkMessagesOnlyFromToday");
}
};
}
示例13: hasViewWithTextAtPosition
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
public static ViewAssertion hasViewWithTextAtPosition(final int index, final CharSequence text) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
if (!(view instanceof RecyclerView)) {
throw e;
}
RecyclerView rv = (RecyclerView) view;
ArrayList<View> outviews = new ArrayList<>();
rv.findViewHolderForAdapterPosition(index).itemView.findViewsWithText(outviews, text,
FIND_VIEWS_WITH_TEXT);
Truth.assert_().withFailureMessage("There's no view at index " + index + " of recyclerview that has text : " + text)
.that(outviews).isNotEmpty();
}
};
}
示例14: doesntHaveViewWithText
import android.support.test.espresso.ViewAssertion; //导入依赖的package包/类
public static ViewAssertion doesntHaveViewWithText(final String text) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException e) {
if (!(view instanceof RecyclerView)) {
throw e;
}
RecyclerView rv = (RecyclerView) view;
ArrayList<View> outviews = new ArrayList<>();
for (int index = 0; index < rv.getAdapter().getItemCount(); index++) {
rv.findViewHolderForAdapterPosition(index).itemView.findViewsWithText(outviews, text,
FIND_VIEWS_WITH_TEXT);
if (outviews.size() > 0) break;
}
Truth.assertThat(outviews).isEmpty();
}
};
}
示例15: checkView
import android.support.test.espresso.ViewAssertion; //导入依赖的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;
}