Java 类android.support.test.espresso.contrib.PickerActions 实例源码

项目:orgzly-android    文件:AgendaFragmentTest.java   
@Test
public void testShiftRepeaterTaskToTomorrow() {
    DateTime tomorrow = DateTime.now().withTimeAtStartOfDay().plusDays(1);

    defaultSetUp();
    openAgenda();
    onListItem(2).perform(swipeRight());
    onListItem(2).onChildView(withId(R.id.item_menu_schedule_btn)).perform(click());
    onView(withId(R.id.dialog_timestamp_date_picker)).perform(click());
    onView(withClassName(equalTo(DatePicker.class.getName())))
            .perform(PickerActions.setDate(
                    tomorrow.getYear(),
                    tomorrow.getMonthOfYear(),
                    tomorrow.getDayOfMonth()));
    onView(withText(R.string.ok)).perform(click());
    onView(withText(R.string.set)).perform(click());
    onView(allOf(withId(android.R.id.list), isDisplayed())).check(matches(listViewItemCount(21)));
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testClickDepartureDate() {
    onView(withId(R.id.departureDateTextView)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).check(matches(isDisplayed()));

    // set date to 10 days ahead
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 10);

    // set date to datePicker dialog
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName())))
            .perform(PickerActions.setDate(
                    calendar.get(Calendar.YEAR),
                    calendar.get(Calendar.MONTH)+1,
                    calendar.get(Calendar.DAY_OF_MONTH)));

    // click ok on the datePicker dialog
    onView(withId(android.R.id.button1)).perform(click());

    // validate label is set same as date set
    onView(withId(R.id.departureDateTextView))
            .check(matches(withText(mSimpleDateFormat.format(calendar.getTime()))));
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testClickDepartureDateCancel() {
    onView(withId(R.id.departureDateTextView)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).check(matches(isDisplayed()));

    // get departureDateTextView value
    String departure = ((TextView) mActivityRule.getActivity().findViewById(R.id.departureDateTextView)).getText().toString();

    // set date to 10 days ahead
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 10);

    // set date to datePicker dialog
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName())))
            .perform(PickerActions.setDate(
                    calendar.get(Calendar.YEAR),
                    calendar.get(Calendar.MONTH)+1,
                    calendar.get(Calendar.DAY_OF_MONTH)));

    // click cancel on the datePicker dialog
    onView(withId(android.R.id.button2)).perform(click());

    // validate label has not changed
    onView(withId(R.id.departureDateTextView))
            .check(matches(withText(departure)));
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testClickReturnDate() {
    onView(withId(R.id.returnDateTextView)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).check(matches(isDisplayed()));

    // set date to 20 days ahead.
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 20);

    // set date to datePicker dialog
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName())))
            .perform(PickerActions.setDate(
                    calendar.get(Calendar.YEAR),
                    calendar.get(Calendar.MONTH)+1,
                    calendar.get(Calendar.DAY_OF_MONTH)));

    // click ok on the datePicker dialog
    onView(withId(android.R.id.button1)).perform(click());

    // validate label is set same as date set
    onView(withId(R.id.returnDateTextView))
            .check(matches(withText(mSimpleDateFormat.format(calendar.getTime()))));
}
项目:FlightSearch    文件:SearchFlightsTest.java   
@Test
public void testClickReturnDateCancel() {
    onView(withId(R.id.returnDateTextView)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).check(matches(isDisplayed()));

    // get return date textview value
    String textViewValue = ((TextView) mActivityRule.getActivity().findViewById(R.id.returnDateTextView)).getText().toString();

    // set date to 20 days ahead.
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 20);

    // set date to datePicker dialog
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName())))
            .perform(PickerActions.setDate(
                    calendar.get(Calendar.YEAR),
                    calendar.get(Calendar.MONTH)+1,
                    calendar.get(Calendar.DAY_OF_MONTH)));

    // click cancel on the datePicker dialog
    onView(withId(android.R.id.button2)).perform(click());

    // validate label has not changed
    onView(withId(R.id.returnDateTextView))
            .check(matches(withText(textViewValue)));
}
项目:aws-device-farm-sample-app-for-android    文件:DatePickerTest.java   
/**
 * Tests a date picker by inputting a date in the date picker then validating
 * if the date is displayed.
 */
@Test
public void testDatePicker(){
    onView(withId(R.id.input_datepicker)).perform(PickerActions.setDate(2015, 10, 27));
    checkIfIdIsDisplayedWithText(R.id.input_date_display, "10/27/2015");
}
项目:aws-device-farm-sample-app-for-android    文件:TimePickerTest.java   
/**
 * Tests a time picker by setting the time and checking the time display
 */
@Test
public void testTimePicker() {
    onView(withId(R.id.input_timepicker)).perform(PickerActions.setTime(8, 2));
    checkIfIdIsDisplayedWithText(R.id.input_time_display, "8 : 02");
}
项目:Bill-Calculator    文件:FormTester.java   
public DatePickerTester pickDate(int day, Month month, int year) {
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName())))
            .perform(PickerActions.setDate(year, month.getValue(), day));
    return this;
}
项目:openScale    文件:UserAddTest.java   
@Test
public void userAddTest() {
    mActivityTestRule.launchActivity(null);

    ViewInteraction editText = onView(
            allOf(withId(R.id.txtUserName),
                    childAtPosition(
                            allOf(withId(R.id.rowUserName),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            0)),
                            1)));
    editText.perform(scrollTo(), click());

    ViewInteraction editText2 = onView(
            allOf(withId(R.id.txtUserName),
                    childAtPosition(
                            allOf(withId(R.id.rowUserName),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            0)),
                            1)));
    editText2.perform(scrollTo(), replaceText("test"), closeSoftKeyboard());

    ViewInteraction editText3 = onView(
            allOf(withId(R.id.txtBodyHeight),
                    childAtPosition(
                            allOf(withId(R.id.rowBodyHeight),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            1)),
                            1)));
    editText3.perform(scrollTo(), replaceText("180"), closeSoftKeyboard());

    onView(withId(R.id.txtBirthday)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).perform(PickerActions.setDate(1990,  1, 19));
    onView(withId(android.R.id.button1)).perform(click());

    ViewInteraction editText5 = onView(
            allOf(withId(R.id.txtInitialWeight),
                    childAtPosition(
                            allOf(withId(R.id.tableRowInitialWeight),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            5)),
                            1)));
    editText5.perform(scrollTo(), replaceText("80"), closeSoftKeyboard());

    ViewInteraction editText6 = onView(
            allOf(withId(R.id.txtGoalWeight),
                    childAtPosition(
                            allOf(withId(R.id.rowGoalWeight),
                                    childAtPosition(
                                            withId(R.id.tableUserData),
                                            6)),
                            1)));
    editText6.perform(scrollTo(), replaceText("60"), closeSoftKeyboard());

    onView(withId(R.id.txtGoalDate)).perform(click());
    onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).perform(PickerActions.setDate(2018,  1, 31));
    onView(withId(android.R.id.button1)).perform(click());

    ViewInteraction button3 = onView(
            allOf(withId(R.id.btnOk),
                    childAtPosition(
                            childAtPosition(
                                    withClassName(is("android.widget.LinearLayout")),
                                    1),
                            2)));
    button3.perform(scrollTo(), click());
}
项目:Ironhide    文件:DatePicker.java   
/**
 * @see android.support.test.espresso.contrib.PickerActions#setDate(int, int, int)
 * @return The model reached by interacting with this element.
 */
public T setDate(int year, int monthOfYear, int dayOfMonth) {
    return performAction(PickerActions.setDate(year, monthOfYear, dayOfMonth));
}
项目:Ironhide    文件:DatePicker.java   
/**
 * @see android.support.test.espresso.contrib.PickerActions#setTime(int, int)
 * @return The model reached by interacting with this element.
 */
public T setTime(int hours, int minutes) {
    return performAction(PickerActions.setTime(hours, minutes));
}
项目:akvo-caddisfly    文件:MiscTest.java   
@Test
    @RequiresDevice
    public void testRestartAppDuringAnalysis() {

        onView(withText(R.string.calibrate)).perform(click());

        onView(withText(currentHashMap.get("fluoride"))).perform(click());

        if (TestUtil.isEmulator()) {

            onView(withText(R.string.errorCameraFlashRequired))
                    .inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow()
                            .getDecorView())))).check(matches(isDisplayed()));
            return;
        }

        DecimalFormatSymbols dfs = new DecimalFormatSymbols();

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

        onView(withId(R.id.editBatchCode))
                .perform(typeText("TEST 123#*@!"), closeSoftKeyboard());

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

        onView(withClassName((Matchers.equalTo(DatePicker.class.getName()))))
                .perform(PickerActions.setDate(2025, 8, 25));

        onView(withId(android.R.id.button1)).perform(click());

        onView(withText(R.string.save)).perform(click());

        onView(allOf(withId(R.id.calibrationList),
                childAtPosition(withClassName(is("android.widget.RelativeLayout")),
                        3))).perform(actionOnItemAtPosition(4, click()));

//        onView(withText("2" + dfs.getDecimalSeparator() + "0 mg/l")).perform(click());

        //onView(withId(R.id.buttonStart)).perform(click());

        mDevice.pressHome();

        try {
            mDevice.pressRecentApps();
        } catch (RemoteException e) {
            Timber.e(e);
        }

        sleep(2000);

        mDevice.click(mDevice.getDisplayWidth() / 2, (mDevice.getDisplayHeight() / 2) + 300);

        mDevice.click(mDevice.getDisplayWidth() / 2, (mDevice.getDisplayHeight() / 2) + 300);

        mDevice.click(mDevice.getDisplayWidth() / 2, (mDevice.getDisplayHeight() / 2) + 300);

        mDevice.waitForWindowUpdate("", 1000);

        //clickListViewItem("Automated Tests");

        clickListViewItem("test caddisfly");

    }