Java Code Examples for android.support.test.espresso.Espresso#closeSoftKeyboard()

The following examples show how to use android.support.test.espresso.Espresso#closeSoftKeyboard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryHelperTest.java    From android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectedImageIsSet() {

  Matcher<Intent> expectedIntent = allOf(hasAction(Intent.ACTION_PICK),
      hasData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
  intending(expectedIntent).respondWith(result);

  Espresso.onView(withId(R.id.gallery_button)).perform(click());
  Espresso.closeSoftKeyboard();
  try {
    Thread.sleep(1000);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  intended(expectedIntent);
}
 
Example 2
Source File: LoginActivityTest.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if all the views are visible on the login activity
 */
@Test
public void checkAllViewAreVisible() throws Exception {
    mLoginActivityActivityTestRule.launchActivity(null);
    onView(withId(R.id.logo)).check(matches(isDisplayed()));
    onView(withId(R.id.tvAppName)).check(matches(withText(R.string.app_name)));
    onView(withId(R.id.loginlayout)).check(matches(isDisplayed()));
    onView(withId(R.id.myExperimentIcon)).check(matches(isDisplayed()));
    onView(withId(R.id.input_layout_email)).check(matches(isDisplayed()));
    onView(withId(R.id.input_layout_password)).check(matches(isDisplayed()));
    onView(withId(R.id.etEmail)).check(matches(isDisplayed()));
    onView(withId(R.id.etPassword)).check(matches(isDisplayed()));
    Espresso.closeSoftKeyboard();
    onView(withId(R.id.bLogin)).check(matches(isDisplayed()));
    onView(withId(R.id.bRegister)).check(matches(isDisplayed()));
}
 
Example 3
Source File: InjectStringExtrasTest.java    From PrettyBundle with Apache License 2.0 5 votes vote down vote up
public void testStartActivityTestStringExtra2UsingDefaultValue() throws Exception {
    final String extra2 = "Nguyen";
    Espresso.onView(ViewMatchers.withHint(R.string.string_extra_2)).perform(ViewActions.typeText(extra2));

    Espresso.closeSoftKeyboard();

    Espresso.onView(ViewMatchers.withText(R.string.submit)).perform(ExtViewActions.waitForSoftKeyboard(), ViewActions.click());

    Espresso.onView(ViewMatchers.withText("Default")).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    Espresso.onView(ViewMatchers.withText(extra2)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
}
 
Example 4
Source File: InjectPrimaryTypeExtrasTest.java    From PrettyBundle with Apache License 2.0 5 votes vote down vote up
public void testStartPrimaryTypeDisplayWithExtras() throws Exception {
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override public void run() {
            ((CheckBox) activity.findViewById(R.id.cbBoolean)).setChecked(true);
        }
    });
    final String integerExtra = "1";
    Espresso.onView(ViewMatchers.withHint(R.string.hint_int)).perform(ViewActions.typeText(integerExtra), ViewActions.pressImeActionButton());
    final String longExtra = "2";
    Espresso.onView(ViewMatchers.withHint(R.string.hint_long)).perform(ViewActions.typeText(longExtra), ViewActions.pressImeActionButton());
    final String floatExtra = "3.4";
    Espresso.onView(ViewMatchers.withHint(R.string.hint_float)).perform(ViewActions.typeText(floatExtra), ViewActions.pressImeActionButton());
    final String doubleExtra = "5.6";
    Espresso.onView(ViewMatchers.withHint(R.string.hint_double)).perform(ViewActions.typeText(doubleExtra), ViewActions.pressImeActionButton());
    final String stringExtra = "String value";
    Espresso.onView(ViewMatchers.withHint(R.string.hint_string)).perform(ViewActions.typeText(stringExtra), ViewActions.pressImeActionButton());
    final String charSequenceExtra = "CharSequence value";
    Espresso.onView(ViewMatchers.withHint(R.string.hint_char_sequence)).perform(ViewActions.typeText(charSequenceExtra), ViewActions.pressImeActionButton());

    Espresso.closeSoftKeyboard();

    Espresso.onView(ViewMatchers.withText(R.string.submit)).perform(ExtViewActions.waitForSoftKeyboard(), ViewActions.scrollTo(), ViewActions.click());

    Espresso.onView(ViewMatchers.withText(integerExtra)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    Espresso.onView(ViewMatchers.withText(longExtra)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    Espresso.onView(ViewMatchers.withText(floatExtra)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    Espresso.onView(ViewMatchers.withText(doubleExtra)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    Espresso.onView(ViewMatchers.withText("true")).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    Espresso.onView(ViewMatchers.withText(stringExtra)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    Espresso.onView(ViewMatchers.withText(charSequenceExtra)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
}
 
Example 5
Source File: ItClickerActivity.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
     * Test the click on the button for the "clean all" feature
     *
     * <i>If the button to clean all is clicked, the configuration / values ion the fields have to be the default values, and the list of points has to be cleaned</i>
     * <i>If the button to clean all is clicked and no values has been changed, the values still remain the default ones</i>
     */
    @Test
    public void clickCleanAll(){

        l(this, "@Test clickCleanAll");

        try {

            // Get the menu item
            UiObject mi = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/action_clean_all")
            );

            // Add some values
            UiObject delayField = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etDelay")
            );
            delayField.setText("007");

            Espresso.closeSoftKeyboard();

            w(1000);
            UiObject repeatField = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etRepeat")
            );
            repeatField.setText("42");
            Espresso.closeSoftKeyboard();
            w(1000);
            UiObject timeGapField = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etTimeBeforeEachClick")
            );
            timeGapField.setText("123");
            Espresso.closeSoftKeyboard();
            w(1000);
            UiObject endless = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scEndlessRepeat")
            );
            endless.click();
            w(1000);

            // Swipe to display items
            UiObject swipeableLayout = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH+":id/clickerActivityMainLayout")
            );
            swipeableLayout.swipeUp(100);

            UiObject vibrateOnStart = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scVibrateOnStart")
            );
            vibrateOnStart.click();
            w(1000);
            UiObject vibrateOnClick = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scVibrateOnClick")
            );
            vibrateOnClick.click();
            w(1000);
            UiObject notifications = mDevice.findObject(
                    new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scNotifOnClick")
            );
            notifications.click();
            w(1000);

            fillSpinnerAsUser();

            // Click on the menu item
            mi.click();

            // Check if the values have been made empty
            assertEquals(Config.DEFAULT_DELAY, delayField.getText());
            assertEquals(Config.DEFAULT_TIME_GAP, timeGapField.getText());
            assertEquals(Config.DEFAULT_REPEAT, repeatField.getText());
            assertEquals(Config.DEFAULT_REPEAT_ENDLESS, endless.isChecked());
            assertEquals(Config.DEFAULT_VIBRATE_ON_START, vibrateOnStart.isChecked());
            assertEquals(Config.DEFAULT_VIBRATE_ON_CLICK, vibrateOnClick.isChecked());
            assertEquals(Config.DEFAULT_NOTIF_ON_CLICK, notifications.isChecked());
//            onView(withId(R.id.clickerActivityMainLayout)).perform(swipeUp());
//            onView(withId(R.id.sPointsToClick)).perform(click());
//            onView(withId(R.id.sPointsToClick)).check(ViewAssertions.matches(withListSize(1)));

            // Test again to check if the default values remain
            mi.click();
            assertEquals(Config.DEFAULT_DELAY, delayField.getText());
            assertEquals(Config.DEFAULT_TIME_GAP, timeGapField.getText());
            assertEquals(Config.DEFAULT_REPEAT, repeatField.getText());
            assertEquals(Config.DEFAULT_REPEAT_ENDLESS, endless.isChecked());
            assertEquals(Config.DEFAULT_VIBRATE_ON_START, vibrateOnStart.isChecked());
            assertEquals(Config.DEFAULT_VIBRATE_ON_CLICK, vibrateOnClick.isChecked());
            assertEquals(Config.DEFAULT_NOTIF_ON_CLICK, notifications.isChecked());
//            onView(withId(R.id.sPointsToClick)).check(ViewAssertions.matches(withListSize(1)));

        } catch ( Exception e ){
            e.printStackTrace();
            fail( e.getMessage() );
        }

    }
 
Example 6
Source File: SignupActivitySteps.java    From CucumberEspressoDemo with MIT License 4 votes vote down vote up
@When("^I tap login button$")
    public void I_tap_login_button() {
//        Close the keyboard else the login button is not available for click on the screen
        Espresso.closeSoftKeyboard();
        onView(withId(R.id.login)).perform(click());
    }