android.support.test.espresso.Espresso#closeSoftKeyboard ( )源码实例Demo

下面列出了android.support.test.espresso.Espresso#closeSoftKeyboard ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-sdk   文件: GalleryHelperTest.java
@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);
}
 
/**
 * 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()));
}
 
源代码3 项目: PrettyBundle   文件: InjectStringExtrasTest.java
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()));
}
 
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()));
}
 
源代码5 项目: SmoothClicker   文件: ItClickerActivity.java
/**
     * 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() );
        }

    }
 
@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());
    }