Java Code Examples for android.support.test.espresso.matcher.ViewMatchers

The following are top voted examples for showing how to use android.support.test.espresso.matcher.ViewMatchers. 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: Ristretto   File: OnViewAllOfWithIsDisplayedNoImport.java   View source code 6 votes vote down vote up
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());
}
 
Example 2
Project: orgzly-android   File: EspressoUtils.java   View source code 6 votes vote down vote up
/**
 * 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);
        }
    };
}
 
Example 3
Project: NumberPadTimePicker   File: NumberPadTimePickerDialogTest.java   View source code 6 votes vote down vote up
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));
}
 
Example 4
Project: android-architecture-components   File: MainActivityTest.java   View source code 6 votes vote down vote up
@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(""))));

}
 
Example 5
Project: cortado   File: Cortado_Tests.java   View source code 6 votes vote down vote up
@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);
}
 
Example 6
Project: RxJavaEspressoSample   File: ActivityCountingIdlingResourceTest.java   View source code 5 votes vote down vote up
@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")));
}
 
Example 7
Project: ChimpCheck   File: PropertyActivityManager.java   View source code 5 votes vote down vote up
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;
}
 
Example 8
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@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));
}
 
Example 9
Project: 2017.1-Trezentos   File: ExamsFragmentInstrumentedTest.java   View source code 5 votes vote down vote up
@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);
}
 
Example 10
Project: encryptedprefs   File: SharedPreferencesReadWriteTest.java   View source code 5 votes vote down vote up
@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());
}
 
Example 11
Project: TestCoverageReport-Android   File: MainActivityInstrumentalTest.java   View source code 5 votes vote down vote up
@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)));
}
 
Example 12
Project: 2017.1-Trezentos   File: UserAccountInstrumentedTest.java   View source code 5 votes vote down vote up
@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")));
}
 
Example 13
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void hasSibling_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<View> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.hasSibling(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.hasSibling(testMatcher));
}
 
Example 14
Project: encryptedprefs   File: SharedPreferencesReadWriteTest.java   View source code 5 votes vote down vote up
@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();
}
 
Example 15
Project: encryptedprefs   File: SharedPreferencesReadWriteTest.java   View source code 5 votes vote down vote up
@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());
}
 
Example 16
Project: encryptedprefs   File: SharedPreferencesReadWriteTest.java   View source code 5 votes vote down vote up
@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());
}
 
Example 17
Project: encryptedprefs   File: SharedPreferencesReadWriteTest.java   View source code 5 votes vote down vote up
@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());
}
 
Example 18
Project: encryptedprefs   File: SharedPreferencesReadWriteTest.java   View source code 5 votes vote down vote up
@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());
}
 
Example 19
Project: TherapyGuide   File: SettingsActions.java   View source code 5 votes vote down vote up
@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);
        }
    };
}
 
Example 20
Project: 2017.1-Trezentos   File: ClassFragmentInstrumentedTest.java   View source code 5 votes vote down vote up
@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);

}
 
Example 21
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void hasDescendant_withCortadoMatcher_addsCorrectMatcher() {
    //given
    Matcher testMatcher = Cortado.view().withText("Test");

    //when
    notCompletable.hasDescendant(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.hasDescendant(testMatcher));
}
 
Example 22
Project: NumberPadTimePicker   File: NumberPadTimePickerDialogTest.java   View source code 5 votes vote down vote up
/**
 * 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));
}
 
Example 23
Project: RxJavaEspressoSample   File: ActivityAsyncTaskExecutorTest.java   View source code 5 votes vote down vote up
@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")));
}
 
Example 24
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void withSpinnerText_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<String> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.withSpinnerText(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withSpinnerText(testMatcher));
}
 
Example 25
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void withText_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<String> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.withText(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withText(testMatcher));
}
 
Example 26
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void hasFocus_addsCorrectMatcher() {
    //given
    //when
    notCompletable.hasFocus();

    //then
    assertExpectedAddedMatcher(ViewMatchers.hasFocus());
}
 
Example 27
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void isEnabled_addsCorrectMatcher() {
    //given
    //when
    notCompletable.isEnabled();

    //then
    assertExpectedAddedMatcher(ViewMatchers.isEnabled());
}
 
Example 28
Project: cortado   File: Cortado_Tests.java   View source code 5 votes vote down vote up
@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);
}
 
Example 29
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void withEffectiveVisibility_addsCorrectMatcher() {
    //given
    ViewMatchers.Visibility testVisibility = ViewMatchers.Visibility.GONE;

    //when
    notCompletable.withEffectiveVisibility(testVisibility);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withEffectiveVisibility(testVisibility));
}
 
Example 30
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@SuppressLint("ResourceType")
@Test
public void withHint_withResource_addsCorrectMatcher() {
    //given
    //when
    notCompletable.withHint(1);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withHint(1));
}
 
Example 31
Project: cortado   File: Cortado.java   View source code 5 votes vote down vote up
@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;
}
 
Example 32
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void withHint_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<String> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.withHint(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withHint(testMatcher));
}
 
Example 33
Project: ZeroKit-Android-Sample   File: SampleAppTest.java   View source code 5 votes vote down vote up
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);
}
 
Example 34
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void isDisplayingAtLeast_addsCorrectMatcher() {
    //given
    //when
    notCompletable.isDisplayingAtLeast(5);

    //then
    assertExpectedAddedMatcher(ViewMatchers.isDisplayingAtLeast(5));
}
 
Example 35
Project: 2017.1-Trezentos   File: ExamsFragmentInstrumentedTest.java   View source code 5 votes vote down vote up
@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);
}
 
Example 36
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@SuppressLint("ResourceType")
@Test
public void withSpinnerText_withResource_addsCorrectMatcher() {
    //given
    //when
    notCompletable.withSpinnerText(1);

    //then
    assertExpectedAddedMatcher(ViewMatchers.withSpinnerText(1));
}
 
Example 37
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void isCompletelyDisplayed_addsCorrectMatcher() {
    //given
    //when
    notCompletable.isCompletelyDisplayed();
    assertExpectedAddedMatcher(ViewMatchers.isCompletelyDisplayed());
}
 
Example 38
Project: 2017.1-Trezentos   File: UserAccountInstrumentedTest.java   View source code 5 votes vote down vote up
@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")));
}
 
Example 39
Project: cortado   File: NotCompletable_Tests.java   View source code 5 votes vote down vote up
@Test
public void isDescendantOfA_withMatcher_addsCorrectMatcher() {
    //given
    org.hamcrest.Matcher<View> testMatcher = SimpleMatcher.instance();

    //when
    notCompletable.isDescendantOfA(testMatcher);

    //then
    assertExpectedAddedMatcher(ViewMatchers.isDescendantOfA(testMatcher));
}
 
Example 40
Project: cortado   File: Cortado_Tests.java   View source code 5 votes vote down vote up
@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);
}