Java Code Examples for android.support.test.espresso.action.ViewActions

The following are top voted examples for showing how to use android.support.test.espresso.action.ViewActions. 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: NumberPadTimePicker   File: NumberPadTimePickerDialogTest.java   View source code 7 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 2
Project: smart-lens   File: InfoActivityTest.java   View source code 7 votes vote down vote up
@Test
public void checkRealApiResponse() throws Exception {
    WikiHelper.BASE_WIKI_URL = "https://en.wikipedia.org/w/";
    openActivity();

    //Wait for the api call
    Delay.startDelay(TestConfig.DELAY_FOR_REAL_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if there are text?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            INFO_VIEW);
    onView(withId(R.id.wiki_page_tv)).check(ViewAssertions.matches(CustomMatchers.hasText()));
    onView(withId(R.id.wiki_page_iv)).check(ViewAssertions.matches(CustomMatchers.hasImage()));
    Delay.stopDelay();
}
 
Example 3
Project: smart-lens   File: InfoActivityTest.java   View source code 7 votes vote down vote up
@Test
public void checkImageApiResponseFail() throws Exception {
    MockWebServer mockWebServer = startMockWebServer();
    //Success response for the info api
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_info_success_response)));
    //Fail response for the image api.
    mockWebServer.enqueue(new MockResponse().setResponseCode(500));
    openActivity();

    //Wait for mock api
    Delay.startDelay(TestConfig.DELAY_FOR_MOCK_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if there are text?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            INFO_VIEW);
    onView(withId(R.id.wiki_page_tv)).check(ViewAssertions.matches(CustomMatchers.hasText()));
    onView(withId(R.id.wiki_page_iv)).check(ViewAssertions.matches(not(CustomMatchers.hasImage())));

    Delay.stopDelay();
    mockWebServer.shutdown();
}
 
Example 4
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 7 votes vote down vote up
@Test
@MediumTest
public void testSwipeDownToHide() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              ViewActions.swipeDown(), ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_HIDDEN));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 5
Project: smart-lens   File: InfoActivityTest.java   View source code 6 votes vote down vote up
@Test
public void checkInfoNotFoundApiResponse() throws Exception {
    MockWebServer mockWebServer = startMockWebServer();
    //Success response for the info api
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_info_not_found_success_response)));
    //Success response for the image api.
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_image_success_response)));
    openActivity();

    //Wait for mock api
    Delay.startDelay(TestConfig.DELAY_FOR_MOCK_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if is error?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            ERROR_VIEW);

    Delay.stopDelay();
    mockWebServer.shutdown();
}
 
Example 6
Project: smart-lens   File: InfoActivityTest.java   View source code 6 votes vote down vote up
@Test
public void checkInfoApiResponseFail() throws Exception {
    MockWebServer mockWebServer = startMockWebServer();
    //Fail response for the info api.
    mockWebServer.enqueue(new MockResponse().setResponseCode(500));
    //Success response for the image api.
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_image_success_response)));
    openActivity();

    //Wait for mock api
    Delay.startDelay(TestConfig.DELAY_FOR_MOCK_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if error occurred?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            ERROR_VIEW);

    Delay.stopDelay();
    mockWebServer.shutdown();
}
 
Example 7
Project: AdSimasTeam   File: ShowAds.java   View source code 6 votes vote down vote up
@Test
    public void openAd() {

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

        onView(ViewMatchers.withId(R.id.buttonShowAd))
                .perform(ViewActions.click());

//        intended(allOf(
//                hasComponent(hasShortClassName("AdSimasFullActivity"))
//        ));

        onView(ViewMatchers.withText("hardMOB - Promoções"));
    }
 
Example 8
Project: Android-BlogExample   File: MainFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void testWebViewUpdateElementByDisplayed() throws Exception {
    String go = MainFragment.DEFAULT_URL;

    onView(withId(R.id.et_url)).perform(clearText());
    onView(withId(R.id.et_url)).perform(typeText(go)).perform(ViewActions.pressImeActionButton());

    waitWebViewLoad();

    onView(withId(R.id.et_keyword)).perform(clearText()).perform(typeText(JAVASCRIPT_CALL));
    onView(withId(R.id.btn_search)).perform(click());

    onWebView()
            // Find the message element by ID
            .withElement(findElement(Locator.ID, "message"))
            // Verify that the text is displayed
            .check(webMatches(getText(), containsString(JAVASCRIPT_CALL)));
}
 
Example 9
Project: Red-Calorie   File: OverviewActivityTest.java   View source code 6 votes vote down vote up
@Test
public void testCanAddNewMeal() {
    onView(withId(R.id.fab_expand_menu_button)).perform(click());
    onView(withId(R.id.overview_fab_add_meal)).perform(click());
    intended(hasComponent(new ComponentName(getTargetContext(), AddMealActivity.class)));
    onView(withId(R.id.add_meal_content)).check(matches(isDisplayed()));
    onView(withId(R.id.add_meal_name)).perform(typeTextIntoFocusedView("Meal 3"));
    closeSoftKeyboard();
    onView(withId(R.id.add_meal_fab_add_ingredient)).perform(click());
    intended(hasComponent(new ComponentName(getTargetContext(), IngredientsActivity.class)));
    onView(allOf(withId(R.id.ingredients_content), isAssignableFrom(RecyclerView.class)))
            .check(matches(isDisplayed()));
    onView(withText(IngredientActivityTest.exampleIngredients[0].getName())).check(matches(isDisplayed()))
            .perform(click());
    intended(hasComponent(new ComponentName(getTargetContext(), IngredientDetailActivity.class)));
    onView(withText(IngredientActivityTest.exampleIngredients[0].getName())).check(matches(isDisplayed()));
    onView(withHint(R.string.add_meal_ingredient_amount_hint)).perform(click())
            .perform(typeTextIntoFocusedView("200"))
            .perform(ViewActions.closeSoftKeyboard());
    onView(withId(R.id.add_meal_ingredient_accept)).perform(click());
    onView(withText(R.string.add_meal_save_action)).perform(click());
    onView(ViewMatchers.withId(R.id.overview_fab_add_meal)).check(matches(isDisplayed()));
    onView(withText("Meal 3"))
            .check(matches(isDisplayed()));
}
 
Example 10
Project: Red-Calorie   File: TagsActivityTest.java   View source code 6 votes vote down vote up
@Test
    public void testAddNewTag() throws Exception {
        main.launchActivity(null);
        final String tagName = "My tag name";
        onView(ViewMatchers.withId(R.id.tags_fab_add_new)).check(matches(isDisplayed()))
                .perform(click());
        onView(withText(R.string.tags_new_tag_dialog)).check(matches(isDisplayed()));
        onView(withHint(R.string.tags_new_tag_hint)).check(matches(isDisplayed()))
                .perform(ViewActions.typeTextIntoFocusedView(tagName));
        onView(withText(tagName)).check(matches(isDisplayed()));
        onView(withText(android.R.string.ok)).check(matches(isDisplayed()))
                .perform(click());
        onView(withText(tagName)).check(matches(isDisplayed()));

//        onView(withText(R.string.tags_undo)).perform(click());
//        onView(withText(tagName)).check(doesNotExist());
    }
 
Example 11
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 6 votes vote down vote up
public void testErrorWithConfirmPasswordDifferentPassword(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordField)).perform(typeText("123456789"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordConfirmationField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.passwordConfirmationField)).check(matches(hasErrorText("As senhas digitadas sao diferentes")));
}
 
Example 12
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 6 votes vote down vote up
public void testEmailRepeatFields() throws InterruptedException {
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("Augusto"));
    onView(withId(R.id.lastNameField)).perform(typeText("Moreno"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView((withId(R.id.passwordField))).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordConfirmationField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());
    Thread.sleep(400);
    onView(withText("Email já cadastrado!")).inRoot(withDecorView(not(is(getActivity()
            .getWindow().getDecorView())))).check(matches(isDisplayed()));
}
 
Example 13
Project: bluesnap-android-int   File: ShippingFlowTest.java   View source code 6 votes vote down vote up
public void enterCardDetails() throws InterruptedException {
    // Check that the sipping button appears
    onView(withId(R.id.buyNowButton))
            .check(matches(withText("Shipping")));

    onView(withId(R.id.creditCardNumberEditText))
            .perform(typeText(cardNumberGeneratorTest()), ViewActions.closeSoftKeyboard());

    CardFormTesterCommon.fillInAllFieldsWithValidCard();

    onView(withId(R.id.buyNowButton)).perform(click());
    Thread.sleep(2000);
    //TODO: check that the shipping activity is launched.
    CardFormTesterCommon.fillInShippingDetails();
    Thread.sleep(2000);
    onView(withId(R.id.shippingBuyNowButton)).perform(ViewActions.closeSoftKeyboard()).perform(click());
    //TOOD: Verify that flow returns to Payment


}
 
Example 14
Project: 2016.2-WikiLegis   File: LoginFragmentTest.java   View source code 6 votes vote down vote up
public void testWithOnlyWifiIfSelectedInActionBarWithUserLogged() {
    closeSoftKeyboard();
    onView(withId(R.id.emailLoginField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordLoginField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.loginButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.action_profile_logged)).perform(click());
    onView(withText("Configurações de download")).perform(click());
    onView(withText("Apenas wifi")).perform(click());
    onView(withText("Confirmar")).perform(click());

    SharedPreferences session = PreferenceManager.
            getDefaultSharedPreferences(getActivity().getBaseContext());

    assertTrue(session.getInt("NetworkSettings", -1) == 0);
}
 
Example 15
Project: 2016.2-WikiLegis   File: LoginFragmentTest.java   View source code 6 votes vote down vote up
public void testWithWifiAndDataMobileIfSelectedInActionBarWithUserLogged() {
    closeSoftKeyboard();
    onView(withId(R.id.emailLoginField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordLoginField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.loginButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.action_profile_logged)).perform(click());
    onView(withText("Configurações de download")).perform(click());
    onView(withText("Wifi e dados")).perform(click());
    onView(withText("Confirmar")).perform(click());

    SharedPreferences session = PreferenceManager.
            getDefaultSharedPreferences(getActivity().getBaseContext());

    assertTrue(session.getInt("NetworkSettings", -1) == 1);
}
 
Example 16
Project: 2016.2-WikiLegis   File: LoginFragmentTest.java   View source code 6 votes vote down vote up
public void testWithNeverDownloadMobileIfSelectedInActionBarWithUserLogged() {
    closeSoftKeyboard();
    onView(withId(R.id.emailLoginField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordLoginField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.loginButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.action_profile_logged)).perform(click());
    onView(withText("Configurações de download")).perform(click());
    onView(withText("Nunca")).perform(click());
    onView(withText("Confirmar")).perform(click());

    SharedPreferences session = PreferenceManager.
            getDefaultSharedPreferences(getActivity().getBaseContext());

    assertTrue(session.getInt("NetworkSettings", -1) == 2);
}
 
Example 17
Project: Android-BlogExample   File: MainFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void testWebToAndroidScriptCall() throws Exception {
    String go = MainFragment.DEFAULT_URL;

    onView(withId(R.id.et_url)).perform(clearText());
    onView(withId(R.id.et_url)).perform(typeText(go)).perform(ViewActions.pressImeActionButton());

    waitWebViewLoad();

    onWebView()
            // Find the search keyword element by ID
            .withElement(findElement(Locator.ID, "search_keyword"))
            // Clear previous input
            .perform(clearElement())
            // Enter text into the input element
            .perform(DriverAtoms.webKeys(ANDROID_SCRIPT_CALL))
            // Value check. script getValue 'search_keyword'
            .check(webMatches(script("return document.getElementById('search_keyword').value", castOrDie(String.class)), containsString(ANDROID_SCRIPT_CALL)))
            // Find the submit button
            .withElement(findElement(Locator.ID, "updateKeywordBtn"))
            // Simulate a click via javascript
            .perform(webClick());

    onView(withId(R.id.et_keyword)).check(matches(withText(ANDROID_SCRIPT_CALL)));
}
 
Example 18
Project: 2016.2-WikiLegis   File: SearchBillFragmentTest.java   View source code 6 votes vote down vote up
public void testResultSearchExistWithInternet() {
    Boolean isLoggedIn = PreferenceManager.getDefaultSharedPreferences
            (activityOnTest.getBaseContext()).getBoolean("IsLoggedIn", false);

    if(isLoggedIn){
        onView(withId(R.id.action_profile_logged)).perform(click());
        onView(withText("Sair")).perform(click());
    }

    closeSoftKeyboard();

    onView(withText("Visitante")).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.action_search)).perform(click());

    onView(isAssignableFrom(EditText.class)).perform(typeText("Gr"),
            pressKey(KeyEvent.KEYCODE_ENTER));

    closeSoftKeyboard();

    onView(withId(R.id.recycler_view_search))
            .perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));

    onView(withId(R.id.textViewTitleBill)).check(matches(isDisplayed()));
}
 
Example 19
Project: 2016.2-WikiLegis   File: SearchBillFragmentTest.java   View source code 6 votes vote down vote up
public void testResultSearchNotExistWithInternet() {
    Boolean isLoggedIn = PreferenceManager.getDefaultSharedPreferences
            (activityOnTest.getBaseContext()).getBoolean("IsLoggedIn", false);

    if(isLoggedIn){
        onView(withId(R.id.action_profile_logged)).perform(click());
        onView(withText("Sair")).perform(click());
    }

    closeSoftKeyboard();

    onView(withText("Visitante")).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.action_search)).perform(click());

    onView(isAssignableFrom(EditText.class)).perform(typeText("Gremio"),
            pressKey(KeyEvent.KEYCODE_ENTER));

    closeSoftKeyboard();

    onView(withText("Nenhum resultado encontrado!")).inRoot(withDecorView(not(is(getActivity()
            .getWindow().getDecorView())))).check(matches(isDisplayed()));
}
 
Example 20
Project: bluesnap-android-int   File: CCormValidityTest.java   View source code 6 votes vote down vote up
@Test
public void dateFieldValidationCheck() throws InterruptedException {
    //Test validation of invalid Month (56)
    onView(withId(R.id.expDateLabelTextView)).check(matches(not(TestUtils.withCurrentTextColor(Color.RED))));
    onView(withId(R.id.expDateEditText))
            .perform(clearText(), typeText("56 44"), ViewActions.closeSoftKeyboard());
    onView(withId(R.id.buyNowButton)).perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.expDateLabelTextView)).check(matches((TestUtils.withCurrentTextColor(Color.RED))));
    onView(withId(R.id.expDateEditText))
            .perform(clearText());

    //Now enter a valid month
    onView(withId(R.id.expDateEditText))
            .perform(typeText("12 26"), ViewActions.closeSoftKeyboard());

    onView(withId(R.id.buyNowButton)).perform(click());
    onView(withId(R.id.expDateLabelTextView)).check(matches(not(TestUtils.withCurrentTextColor(Color.RED))));
}
 
Example 21
Project: bluesnap-android-int   File: CCormValidityTest.java   View source code 6 votes vote down vote up
@Test
public void dateFieldPastCheck() throws InterruptedException {
    onView(withId(R.id.expDateLabelTextView)).check(matches(not(TestUtils.withCurrentTextColor(Color.RED))));
    onView(withId(R.id.expDateEditText))
            .perform(typeText("11 05"), ViewActions.closeSoftKeyboard());
    onView(withId(R.id.buyNowButton)).perform(click());
    onView(withId(R.id.expDateLabelTextView)).check(matches((TestUtils.withCurrentTextColor(Color.RED))));
    onView(withId(R.id.expDateEditText))
            .perform(clearText());

    //Now enter a valid month
    onView(withId(R.id.expDateEditText))
            .perform(typeText("12 26"), ViewActions.closeSoftKeyboard());

    onView(withId(R.id.buyNowButton)).perform(click());
    onView(withId(R.id.expDateLabelTextView)).check(matches(not(TestUtils.withCurrentTextColor(Color.RED))));
}
 
Example 22
Project: material-components-android   File: BottomSheetBehaviorTouchTest.java   View source code 6 votes vote down vote up
@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));
            }
          });
}
 
Example 23
Project: material-components-android   File: BottomSheetDialogTest.java   View source code 6 votes vote down vote up
@Test
public void testTouchInside() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          showDialog();
          // Confirms that the dialog is shown
          assertThat(dialog.isShowing(), is(true));
          FrameLayout bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
          // The bottom sheet is not clickable
          assertNotNull(bottomSheet);
          assertThat(bottomSheet.isClickable(), is(false));
        }
      });
  // Click on the bottom sheet
  Espresso.onView(ViewMatchers.withId(R.id.design_bottom_sheet)).perform(ViewActions.click());
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          // Confirm that touch didn't fall through as outside touch
          assertThat(dialog.isShowing(), is(true));
        }
      });
}
 
Example 24
Project: material-components-android   File: BottomSheetDialogTest.java   View source code 6 votes vote down vote up
@Test
public void testClickContent() throws Throwable {
  final View.OnClickListener mockListener = mock(View.OnClickListener.class);
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          showDialog();
          // Confirms that the dialog is shown
          assertThat(dialog.isShowing(), is(true));
          FrameLayout bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
          // Set up an OnClickListener to the content of the bottom sheet
          assertNotNull(bottomSheet);
          View child = bottomSheet.getChildAt(0);
          child.setOnClickListener(mockListener);
        }
      });
  // Click on the bottom sheet; since the whole sheet is occupied with its only child, this
  // clicks the child
  Espresso.onView(ViewMatchers.withParent(ViewMatchers.withId(R.id.design_bottom_sheet)))
      .perform(ViewActions.click());
  verify(mockListener, times(1)).onClick(any(View.class));
}
 
Example 25
Project: material-components-android   File: BottomSheetDialogTest.java   View source code 6 votes vote down vote up
@Test
public void testNonCancelableDialog() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          showDialog();
          dialog.setCancelable(false);
        }
      });
  // Click outside the bottom sheet
  Espresso.onView(ViewMatchers.withId(R.id.touch_outside)).perform(ViewActions.click());
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          FrameLayout bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
          BottomSheetBehavior<FrameLayout> behavior = BottomSheetBehavior.from(bottomSheet);
          assertThat(behavior.isHideable(), is(false));
          assertThat(dialog.isShowing(), is(true));
          dialog.cancel();
          assertThat(dialog.isShowing(), is(false));
        }
      });
}
 
Example 26
Project: RecipeFinderJavaVersion   File: SearchRecipesFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void testStartSearching() {
    when(repository.searchRecipes(Mockito.<String, String>anyMap()))
            .thenReturn(Single.just(AssetUtils.getRecipeList(context)));
    when(repository.loadMore(Mockito.<String, String>anyMap()))
            .thenReturn(Single.just(AssetUtils.getMoreRecipeList(context)));
    when(repository.isInFavorites(Mockito.<Recipe>any()))
            .thenReturn(Single.just(true));
    rule.launchActivity(new Intent());
    performSearch();

    onView(withText(firstRecipeTitle)).check(matches(isDisplayed()));
    onView(ViewMatchers.withId(R.id.rv_recipe_list)).perform(RecyclerViewActions.scrollToPosition(9));
    onView(withText(lastRecipeTitle)).check(matches(isDisplayed()));

    // Scroll to top and click upon the first item
    Recipe recipe = AssetUtils.getRecipeEntity(InstrumentationRegistry.getContext());
    onView(withId(R.id.rv_recipe_list)).perform(RecyclerViewActions.scrollToPosition(0));

    onView(withText(recipe.getLabel())).perform(ViewActions.click());

    onView(withId(R.id.tv_health_labels)).check(matches(isDisplayed()));
    onView(withId(R.id.iv_recipe_image)).check(matches(isDisplayed()));
    onView(withId(R.id.toolbar)).check(matches(isDisplayed()));
}
 
Example 27
Project: bluesnap-android-int   File: CCormValidityTest.java   View source code 6 votes vote down vote up
@Test
public void invalidCardMessageCheck() throws InterruptedException {
    //Test validation of invalid number
    onView(withId(R.id.invaildCreditCardMessageTextView)).check(matches(not(ViewMatchers.isDisplayed())));
    onView(withId(R.id.creditCardNumberEditText))
            .perform(typeText(invalidCardNumberGeneratorTest()), ViewActions.closeSoftKeyboard());
    onView(withId(R.id.buyNowButton)).perform(click());
    onView(withId(R.id.invaildCreditCardMessageTextView)).check(matches(ViewMatchers.isDisplayed()));

    //Clear the invalid number
    onView(withId(R.id.creditCardNumberEditText)).perform(clearText());

    //Put a valid number
    onView(withId(R.id.creditCardNumberEditText))
            .perform(typeText(cardNumberGeneratorTest()), ViewActions.closeSoftKeyboard());
    onView(withId(R.id.buyNowButton)).perform(click());
    onView(withId(R.id.invaildCreditCardMessageTextView)).check(matches(not(ViewMatchers.isDisplayed())));
}
 
Example 28
Project: smart-lens   File: InfoActivityTest.java   View source code 5 votes vote down vote up
@Test
public void checkInfoFoundApiResponse() throws Exception {
    MockWebServer mockWebServer = startMockWebServer();
    //Success response for the info api
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_info_success_response)));
    //Success response for the image api.
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_image_success_response)));
    openActivity();

    //Wait for mock api
    Delay.startDelay(TestConfig.DELAY_FOR_REAL_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if there are text?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            INFO_VIEW);
    onView(withId(R.id.wiki_page_tv)).check(ViewAssertions.matches(CustomMatchers.hasText()));
    onView(withId(R.id.wiki_page_iv)).check(ViewAssertions.matches(CustomMatchers.hasImage()));

    Delay.stopDelay();
    mockWebServer.shutdown();
}
 
Example 29
Project: Clases-2017c1   File: SelectPictureActivityTest.java   View source code 5 votes vote down vote up
@Test
public void checkDownloadUrl() {
    // CountingIdleResource sirve para sincronizar tests cuando se ejecutan tareas asíncronas.
    // En este caso pausa el avance del test mientras descarga un archivo y eso lo hicimos
    // pisando el Factory de UrlRequest para que lo utilice.
    onView(withId(R.id.urlEditText)).perform(ViewActions.typeText("http://esotericos.org/wp-content/uploads/2012/08/Buscar-la-felicidad.jpg"));
    // La siguiente instrucción detiene el test porque arranca una descarga:
    onView(withId(R.id.urlButton)).perform(click());
    // La siguiente instrucción se ejecuta una vez que la descarga termina:
    onView(withId(R.id.progressBar)).check(matches(not(isDisplayed())));
}
 
Example 30
Project: bluesnap-android-int   File: CCormValidityTest.java   View source code 5 votes vote down vote up
/**
 * Test that when entering valid data and then modifying it eventually invalidates the form.
 *
 * @throws InterruptedException
 */
@Test
public void test_validate_invalidate() throws InterruptedException {
    CardFormTesterCommon.fillInAllFieldsWithValidCard();

    onView(withId(R.id.creditCardNumberEditText))
            .perform(ViewActions.closeSoftKeyboard())
            //.perform(pressKey(KeyEvent.KEYCODE_DEL))
            .perform(clearText())
            .perform(typeText("1"), ViewActions.closeSoftKeyboard());

    onView(withId(R.id.buyNowButton)).perform(click());
    onView(withId(R.id.invaildCreditCardMessageTextView)).check(matches(ViewMatchers.isDisplayed()));
}
 
Example 31
Project: bluesnap-android-int   File: CardFormTesterCommon.java   View source code 5 votes vote down vote up
public static void fillInShippingDetails() {
    onView(withId(R.id.shippingNameEditText)).perform(clearText(), typeText("John Doe"));
    onView(withId(R.id.shippingAddressLine)).perform(clearText(), typeText("9 Baker street"));
    onView(withId(R.id.shippingCityEditText)).perform(clearText(), typeText("London"));
    onView(withId(R.id.shippingStateEditText)).perform(clearText(), typeText("UK")).perform(ViewActions.closeSoftKeyboard());

}
 
Example 32
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithNumbersFirstName(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaa125"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).check(matches(hasErrorText("O nome deve ter apenas letras.")));
}
 
Example 33
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithNumbersLastName(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaa125"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.lastNameField)).check(matches(hasErrorText("O sobrenome deve ter apenas letras.")));
}
 
Example 34
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithEmptyEmail(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText(""));
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.emailField)).check(matches(hasErrorText("Inválido, o email não pode ser vazio.")));
}
 
Example 35
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithOverMaxLengthEmail(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[email protected]gmail.com"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.emailField)).check(matches(hasErrorText("Inválido, o email deve ter no máximo 150 caractéres")));
}
 
Example 36
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithEmptyPassword(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordField)).perform(typeText(""));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.passwordField)).check(matches(hasErrorText("Inválido, a senha não pode ser vazia.")));
}
 
Example 37
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithLesserMinLengthPassword(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordField)).perform(typeText("1234"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.passwordField)).check(matches(hasErrorText("Inválido, a senha deve conter no mínimo 6 caractéres.")));
}
 
Example 38
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithOverMaxLengthFirstName(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView((withId(R.id.firstNameField))).check(matches(hasErrorText("Inválido, o nome deve ter no máximo 30 caractéres")));
}
 
Example 39
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithEmptyLastName(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaaaaaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText(""));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());
    onView((withId(R.id.lastNameField))).check(matches(hasErrorText("Inválido, o sobrenome não pode ser vazio.")));
}
 
Example 40
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public void testErrorWithOverMaxLengthLastName(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaaaaaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());
    onView((withId(R.id.lastNameField))).check(matches(hasErrorText("Inválido, o sobrenome deve ter no máximo 30 caractéres")));
}