Java 类android.support.test.espresso.matcher.ViewMatchers 实例源码

项目:Ristretto    文件:OnViewAllOfWithIsDisplayedNoImport.java   
public void fooMatchers() {
    Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());

    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
}
项目:orgzly-android    文件:EspressoUtils.java   
/**
 * Set value for {@link NumberPicker}
 */
public static ViewAction setNumber(final int n) {
    return new ViewAction() {
        @Override
        public void perform(UiController uiController, View view) {
            ((NumberPicker) view).setValue(n);
        }

        @Override
        public String getDescription() {
            return "Set NumberPicker value";
        }

        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(NumberPicker.class);
        }
    };
}
项目:NumberPadTimePicker    文件:NumberPadTimePickerDialogTest.java   
private static void verifyViewEnabledStates(TestCase test) {
    ViewInteraction[] buttonsInteractions = getButtonInteractions();
    ViewInteraction[] altButtonsInteractions = getAltButtonInteractions();
    for (int digit : test.sequence) {
        buttonsInteractions[digit]
                .check(ViewAssertions.matches(ViewMatchers.isEnabled()))
                .perform(ViewActions.click());
    }
    for (int i = 0; i < 10; i++) {
        buttonsInteractions[i].check(matchesIsEnabled(
                i >= test.numberKeysEnabledStart && i < test.numberKeysEnabledEnd));
        altButtonsInteractions[0].check(matchesIsEnabled(test.leftAltKeyEnabled));
        altButtonsInteractions[1].check(matchesIsEnabled(test.rightAltKeyEnabled));
    }

    Espresso.onView(ViewMatchers.withText(android.R.string.ok))
            .check(matchesIsEnabled(test.okButtonEnabled));

    ViewInteraction backspaceInteraction = Espresso.onView(
            ViewMatchers.withId(R.id.nptp_backspace));
    // Reset after each iteration by backspacing on the button just clicked.
    backspaceInteraction.check(matchesIsEnabled(true))
            .perform(ViewActions.longClick())
            .check(matchesIsEnabled(false));
}
项目:android-architecture-components    文件:MainActivityTest.java   
@Test
public void clickOnFirstItem_opensComments() throws Throwable {
    drain();
    // When clicking on the first product
    onView(ViewMatchers.withContentDescription(R.string.cd_products_list))
            .perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
    drain();
    // Then the second screen with the comments should appear.
    onView(withContentDescription(R.string.cd_comments_list))
            .check(matches(isDisplayed()));
    drain();
    // Then the second screen with the comments should appear.
    onView(withContentDescription(R.string.cd_product_name))
            .check(matches(not(withText(""))));

}
项目:cortado    文件:Cortado_Tests.java   
@Test
public void addMatcher_negatesMatcher_when_negateNextMatcher_isTrue() {
    final Start.Matcher matcher = Cortado.view();
    final Cortado cortado = matcher.getCortado();
    assertThat(cortado.matchers).hasSize(0);
    assertThat(cortado.negateNextMatcher).isFalse();
    // no matchers added, negateNextMatcher is false

    org.hamcrest.Matcher<View> viewMatcher = ViewMatchers.withText("test");
    org.hamcrest.Matcher<View> negatedViewMatcher = Matchers.not(viewMatcher);

    cortado.negateNextMatcher = true;

    cortado.addMatcher(viewMatcher);
    assertThat(cortado.matchers).hasSize(1);
    // one matcher added

    assertThat(cortado.negateNextMatcher).isFalse();
    // negateNextMatcher is back to false

    final Matcher<? super View> addedMatcher = cortado.matchers.get(0);
    Utils.assertThat(addedMatcher).isNotEqualTo(viewMatcher);
    Utils.assertThat(addedMatcher).isEqualTo(negatedViewMatcher);
}
项目:RxJavaEspressoSample    文件:ActivityCountingIdlingResourceTest.java   
@Test
public void test_wait_debounce() {
    onView(ViewMatchers.withId(R.id.button_debounce)).perform(click());

    // In this case, CountingIdlingResource has no effect.
    // Use UiDevice.wait() of UIAutomator instead.
    uiDevice.wait(Until.hasObject(By.text("Debounce Completed")), 5000L);
    onView(withId(R.id.text_debounce_result))
            .check(matches(withText("Debounce Completed")));
}
项目:ChimpCheck    文件:PropertyActivityManager.java   
protected static Map<String, Matcher<View>>  createMap() {
     Map<String, Matcher<View>> thisMap = new HashMap<String, Matcher<View>>();

     thisMap.put("isClickable", ViewMatchers.isClickable());
     thisMap.put("isDisplayed", ViewMatchers.isDisplayed());
     thisMap.put("isEnabled", ViewMatchers.isEnabled());
     thisMap.put("supportsInputMethods", ViewMatchers.supportsInputMethods());
     thisMap.put("isSelected", ViewMatchers.isSelected());

     return thisMap;
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void withTagKey_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<Object> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.withTagKey(1, testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withTagKey(1, testMatcher));
}
项目:2017.1-Trezentos    文件:ExamsFragmentInstrumentedTest.java   
@Test
public void shouldClickOnExamButton(){
    onView(withId(R.id.salas_item))
            .perform(click());
    onData(anything()).inAdapterView(withId(R.id.recycler))
            .atPosition(0).perform(click());
    onView(ViewMatchers.withText("EXAMS"))
            .perform(click());

    onView(withId(R.id.floating_btn)).perform(click());

    assertNotNull(examRule);
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testString() {
  ViewInteraction appCompatButton = onView(
      allOf(withText("String"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton.perform(click());
}
项目:TestCoverageReport-Android    文件:MainActivityInstrumentalTest.java   
@Test
public void shouldHideButtonAfterClick() {
    // then
    onView(withId(R.id.button_hide)).perform(click());

    // when
    onView(withId(R.id.button_hide)).
            check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
}
项目:2017.1-Trezentos    文件:UserAccountInstrumentedTest.java   
@Test
public void shouldValidateNullEmailLogin() throws UserException{
    onView(ViewMatchers.withId(R.id.edit_text_email))
            .perform(typeText(""));
    closeSoftKeyboard();
    onView(withId(R.id.edit_text_password))
            .perform(typeText("Aluno1"));
    closeSoftKeyboard();
    onView(withId(R.id.button_login))
            .perform(click());

    onView(withId(R.id.edit_text_email)).check(matches(hasErrorText("O email não pode estar vazio")));
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void hasSibling_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<View> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.hasSibling(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.hasSibling(testMatcher));
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testFloat() {

  ViewInteraction appCompatButton5 = onView(
      allOf(withText("Float"),

          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton5.perform();
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testBoolean() {

  ViewInteraction appCompatButton6 = onView(
      allOf(withText("Boolean"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton6.perform(click());
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testContains() {

  ViewInteraction appCompatButton7 = onView(
      allOf(withText("contains"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton7.perform(click());
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testParallelWriteRead() {

  ViewInteraction appCompatButton9 = onView(
      allOf(withText("parallel Write & Read"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton9.perform(click());
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testMissing() {

  ViewInteraction appCompatButton10 = onView(
      allOf(withText("missing"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton10.perform(click());
}
项目:TherapyGuide    文件:SettingsActions.java   
@SuppressWarnings("SameParameterValue")
public static ViewAction setTime(final int hour, final int minute) {
    return new ViewAction() {
        @Override
        public void perform(UiController uiController, View view) {
            TimePicker tp = (TimePicker) view;
            if(android.os.Build.VERSION.SDK_INT < 23) {
                //noinspection deprecation
                tp.setCurrentHour(hour);
                //noinspection deprecation
                tp.setCurrentMinute(minute);
            }
            else {
                tp.setHour(hour);
                tp.setMinute(minute);
            }
        }
        @Override
        public String getDescription() {
            return "Set the passed time into the TimePicker";
        }
        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(TimePicker.class);
        }
    };
}
项目:2017.1-Trezentos    文件:ClassFragmentInstrumentedTest.java   
@Test
public void shouldClickOnClassCreated(){

    ClassFragment classFragment;
    classFragment = (ClassFragment) mainRule.getActivity()
            .getSupportFragmentManager()
            .findFragmentById(frame);

    RecyclerView recyclerView =
            (RecyclerView) classFragment.getActivity()
                    .findViewById(R.id.recycler);

    if(recyclerView.getAdapter().getItemCount() > 0) {

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        onView(ViewMatchers.withId(R.id.recycler))
                .perform(click());

    }

    assertNotNull(classFragment);

}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void hasDescendant_withCortadoMatcher_addsCorrectMatcher() {
    //given
    Matcher testMatcher = Cortado.view().withText("Test");

    //when
    notCompletable.hasDescendant(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.hasDescendant(testMatcher));
}
项目:NumberPadTimePicker    文件:NumberPadTimePickerDialogTest.java   
/**
 * Helper method that wraps {@link ViewMatchers#withText(String) withText(String)}.
 *
 * @return A Matcher that matches a number key button by its text representation
 *         of {@code digit}.
 */
private static Matcher<View> withDigit(int digit) {
    // TODO: When we're comfortable with the APIs, we can statically import them and
    // make direct calls to these methods and cut down on the verbosity, instead of
    // writing helper methods that wrap these APIs.
    return ViewMatchers.withText(text(digit));
}
项目:RxJavaEspressoSample    文件:ActivityAsyncTaskExecutorTest.java   
@Test
public void test_wait_debounce() {
    onView(ViewMatchers.withId(R.id.button_debounce)).perform(click());

    // In this case, CountingIdlingResource has no effect.
    // Use UiDevice.wait() of UIAutomator instead.
    uiDevice.wait(Until.hasObject(By.text("Debounce Completed")), 5000L);
    onView(withId(R.id.text_debounce_result))
            .check(matches(withText("Debounce Completed")));
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void withSpinnerText_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<String> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.withSpinnerText(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withSpinnerText(testMatcher));
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void withText_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<String> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.withText(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withText(testMatcher));
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void hasFocus_addsCorrectMatcher() {
    //given
    //when
    notCompletable.hasFocus();

    //then
    assertExpectedAddedMatcher(ViewMatchers.hasFocus());
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void isEnabled_addsCorrectMatcher() {
    //given
    //when
    notCompletable.isEnabled();

    //then
    assertExpectedAddedMatcher(ViewMatchers.isEnabled());
}
项目:cortado    文件:Cortado_Tests.java   
@Test
public void onTextView_returnsProperViewInteraction() {
    //given
    final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onTextView().withText("test");
    final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
            ViewMatchers.isAssignableFrom(TextView.class),
            viewInteraction.getCortado().matchers.get(0));

    //when
    final Matcher<View> rawMatcher = viewInteraction.getCortado().get();

    //then
    Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void withEffectiveVisibility_addsCorrectMatcher() {
    //given
    ViewMatchers.Visibility testVisibility = ViewMatchers.Visibility.GONE;

    //when
    notCompletable.withEffectiveVisibility(testVisibility);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withEffectiveVisibility(testVisibility));
}
项目:cortado    文件:NotCompletable_Tests.java   
@SuppressLint("ResourceType")
@Test
public void withHint_withResource_addsCorrectMatcher() {
    //given
    //when
    notCompletable.withHint(1);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withHint(1));
}
项目:cortado    文件:Cortado.java   
@NonNull
final synchronized org.hamcrest.Matcher<View> get() {
    if (cached == null) {
        cached = linker.link(matchers);
        if (assignableFromClass != null) {
            List<org.hamcrest.Matcher<? super View>> assignedMatchers = new ArrayList<>(2);
            assignedMatchers.add(ViewMatchers.isAssignableFrom(assignableFromClass));
            assignedMatchers.add(cached);
            cached = Linker.AND.link(assignedMatchers);
        }
    }
    //noinspection unchecked
    return (org.hamcrest.Matcher<View>) cached;
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void withHint_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<String> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.withHint(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withHint(testMatcher));
}
项目:ZeroKit-Android-Sample    文件:SampleAppTest.java   
private void signUp(String userName, String password) throws InterruptedException {
    onView(allOf(withId(R.id.tab_signup), isDisplayed())).perform(click());
    onView(allOf(withId(R.id.editText), isDisplayed())).perform(scrollTo(), click(), typeText(userName), closeSoftKeyboard());
    onView(allOf(withId(R.id.editText2), isDisplayed())).perform(scrollTo(), click(), typeText(password), closeSoftKeyboard());
    onView(allOf(withId(R.id.editText3), isDisplayed())).perform(scrollTo(), click(), typeText(password), closeSoftKeyboard());
    onView(allOf(withId(R.id.button), withText("Sign Up"), withParent(allOf(withId(R.id.constraintLayout), withParent(withId(R.id.signUpFragment)))))).perform(scrollTo(), click());
    onView(withText("Successful sign up")).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
    Thread.sleep(5000);
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void isDisplayingAtLeast_addsCorrectMatcher() {
    //given
    //when
    notCompletable.isDisplayingAtLeast(5);

    //then
    assertExpectedAddedMatcher(ViewMatchers.isDisplayingAtLeast(5));
}
项目:2017.1-Trezentos    文件:ExamsFragmentInstrumentedTest.java   
@Test
public void shouldValidateExamsFragmentInitialization(){
    onView(withId(R.id.salas_item))
            .perform(click());
    onData(anything()).inAdapterView(withId(R.id.recycler))
            .atPosition(0).perform(click());
    onView(ViewMatchers.withText("EXAMS"))
            .perform(click());

    assertNotNull(examRule);
}
项目:cortado    文件:NotCompletable_Tests.java   
@SuppressLint("ResourceType")
@Test
public void withSpinnerText_withResource_addsCorrectMatcher() {
    //given
    //when
    notCompletable.withSpinnerText(1);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withSpinnerText(1));
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void isCompletelyDisplayed_addsCorrectMatcher() {
    //given
    //when
    notCompletable.isCompletelyDisplayed();
    assertExpectedAddedMatcher(ViewMatchers.isCompletelyDisplayed());
}
项目:2017.1-Trezentos    文件:UserAccountInstrumentedTest.java   
@Test
public void shouldValidateNullEmailLogin() throws UserException{
    onView(ViewMatchers.withId(R.id.edit_text_email))
            .perform(typeText(""));
    closeSoftKeyboard();
    onView(withId(R.id.edit_text_password))
            .perform(typeText("Aluno1"));
    closeSoftKeyboard();
    onView(withId(R.id.button_login))
            .perform(click());

    onView(withId(R.id.edit_text_email)).check(matches(hasErrorText("O email não pode estar vazio")));
}
项目:cortado    文件:NotCompletable_Tests.java   
@Test
public void isDescendantOfA_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<View> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.isDescendantOfA(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.isDescendantOfA(testMatcher));
}
项目:cortado    文件:Cortado_Tests.java   
@Test
public void onEditText_returnsProperViewInteraction() {
    //given
    final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onEditText().withText("test");
    final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
            ViewMatchers.isAssignableFrom(EditText.class),
            viewInteraction.getCortado().matchers.get(0));

    //when
    final Matcher<View> rawMatcher = viewInteraction.getCortado().get();

    //then
    Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);
}