androidx.test.rule.ActivityTestRule Java Examples
The following examples show how to use
androidx.test.rule.ActivityTestRule.
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: ActivityUtils.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Restarts the RecreatedAppCompatActivity and waits for the new activity to be resumed. * * @return The newly-restarted RecreatedAppCompatActivity */ @SuppressWarnings("unchecked") // The type of the recreated activity is guaranteed to be T public static <T extends RecreatableAppCompatActivity> T recreateActivity( ActivityTestRule<? extends RecreatableAppCompatActivity> rule, final T activity) throws InterruptedException { // Now switch the orientation RecreatableAppCompatActivity.resumedLatch = new CountDownLatch(1); RecreatableAppCompatActivity.destroyedLatch = new CountDownLatch(1); runOnUiThreadRethrow(rule, activity::recreate); assertTrue(RecreatableAppCompatActivity.resumedLatch.await(1, TimeUnit.SECONDS)); assertTrue(RecreatableAppCompatActivity.destroyedLatch.await(1, TimeUnit.SECONDS)); T newActivity = (T) RecreatableAppCompatActivity.activity; waitForExecution(rule); RecreatableAppCompatActivity.clearState(); return newActivity; }
Example #2
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 6 votes |
public static MaterialDatePicker<Long> showDatePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule, int themeResId, CalendarConstraints calendarConstraints) { FragmentManager fragmentManager = activityTestRule.getActivity().getSupportFragmentManager(); String tag = "Date DialogFragment"; MaterialDatePicker<Long> dialogFragment = MaterialDatePicker.Builder.datePicker() .setCalendarConstraints(calendarConstraints) .setTheme(themeResId) .build(); dialogFragment.show(fragmentManager, tag); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); return dialogFragment; }
Example #3
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 6 votes |
static MaterialDatePicker<Pair<Long, Long>> showRangePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule, int themeResId, CalendarConstraints calendarConstraints) { FragmentManager fragmentManager = activityTestRule.getActivity().getSupportFragmentManager(); String tag = "Date Range DialogFragment"; MaterialDatePicker<Pair<Long, Long>> dialogFragment = MaterialDatePicker.Builder.dateRangePicker() .setCalendarConstraints(calendarConstraints) .setTheme(themeResId) .build(); dialogFragment.show(fragmentManager, tag); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); return dialogFragment; }
Example #4
Source File: MainActivityTest.java From Walk-In-Clinic-Android-App with MIT License | 5 votes |
@Test public void changeText_sameActivity() { onView(withId(R.id.SignInButton)).perform(click()); onView(ViewMatchers.withId(R.id.passwordField2)) .perform(typeText("EspressoUser123"), closeSoftKeyboard()); onView(ViewMatchers.withId(R.id.usernameField2)) .perform(typeText("EspressoUser123"), closeSoftKeyboard()); onView(withId(R.id.signInButton)).perform(click()); while (true) { try { onView(withId(R.id.profileButton)).perform(click()); break; } catch (Exception e) { onView(withId(R.id.signInButton)).perform(click()); continue; } } activityRuleProfile = new ActivityTestRule<>(Profile.class); onView(withId(R.id.addressField2)).perform(replaceText(""), closeSoftKeyboard()); onView(withId(R.id.phoneNumField)).perform(replaceText(""), closeSoftKeyboard()); onView(withId(R.id.nameField)).perform(replaceText(""), closeSoftKeyboard()); onView(withId(R.id.saveButton)).perform(click()); onView(withId(R.id.addressField2)).perform(typeText("100 Bank Street"), closeSoftKeyboard()); onView(withId(R.id.saveButton)).perform(click()); onView(withId(R.id.phoneNumField)).perform(typeText("(905)-806-2222"), closeSoftKeyboard()); onView(withId(R.id.saveButton)).perform(click()); onView(withId(R.id.nameField)).perform(typeText("Test"), closeSoftKeyboard()); onView(withId(R.id.saveButton)).perform(click()); }
Example #5
Source File: ActivityUtils.java From material-components-android with Apache License 2.0 | 5 votes |
private static void runOnUiThreadRethrow( ActivityTestRule<? extends RecreatableAppCompatActivity> rule, Runnable r) { if (Looper.getMainLooper() == Looper.myLooper()) { r.run(); } else { try { rule.runOnUiThread(r); } catch (Throwable t) { throw new RuntimeException(t); } } }
Example #6
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 5 votes |
public static MaterialDatePicker<Long> showDatePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule, int themeResId) { Month start = Month.create(1900, Calendar.JANUARY); Month end = Month.create(2100, Calendar.DECEMBER); CalendarConstraints calendarConstraints = new CalendarConstraints.Builder() .setStart(start.timeInMillis) .setEnd(end.timeInMillis) .setOpenAt(OPENING_TIME) .build(); return showDatePicker(activityTestRule, themeResId, calendarConstraints); }
Example #7
Source File: ActivityUtils.java From material-components-android with Apache License 2.0 | 5 votes |
public static void waitForExecution( final ActivityTestRule<? extends RecreatableAppCompatActivity> rule) { // Wait for two cycles. When starting a postponed transition, it will post to // the UI thread and then the execution will be added onto the queue after that. // The two-cycle wait makes sure fragments have the opportunity to complete both // before returning. try { rule.runOnUiThread(DO_NOTHING); rule.runOnUiThread(DO_NOTHING); } catch (Throwable throwable) { throw new RuntimeException(throwable); } }
Example #8
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 5 votes |
static <S> MaterialDatePicker<S> showPicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule, MaterialDatePicker.Builder<S> builder) { FragmentManager fragmentManager = activityTestRule.getActivity().getSupportFragmentManager(); String tag = "Date Range DialogFragment"; MaterialDatePicker<S> dialogFragment = builder.build(); dialogFragment.show(fragmentManager, tag); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); return dialogFragment; }
Example #9
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 5 votes |
public static MaterialDatePicker<Pair<Long, Long>> showRangePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule, int themeResId) { Month start = Month.create(1900, Calendar.JANUARY); Month end = Month.create(2100, Calendar.DECEMBER); CalendarConstraints calendarConstraints = new CalendarConstraints.Builder() .setStart(start.timeInMillis) .setEnd(end.timeInMillis) .setOpenAt(OPENING_TIME) .build(); return showRangePicker(activityTestRule, themeResId, calendarConstraints); }
Example #10
Source File: RestoreSearchQueryListFragmentTest.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<MoviesActivity> getActivityTestRule() { return mActivityRule; }
Example #11
Source File: AddonsActivityTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<AddonsActivity> getActivityTestRule() { return mActivityRule; }
Example #12
Source File: MoviesActivityTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<MoviesActivity> getActivityTestRule() { return mActivityRule; }
Example #13
Source File: TVShowsActivityTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<TVShowsActivity> getActivityTestRule() { return mActivityRule; }
Example #14
Source File: PlaylistTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<RemoteActivity> getActivityTestRule() { return remoteActivityActivityTestRule; }
Example #15
Source File: KodiPreV17Tests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<RemoteActivity> getActivityTestRule() { return remoteActivityActivityTestRule; }
Example #16
Source File: ButtonTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<RemoteActivity> getActivityTestRule() { return remoteActivityActivityTestRule; }
Example #17
Source File: KodiPreV17Tests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<RemoteActivity> getActivityTestRule() { return remoteActivityActivityTestRule; }
Example #18
Source File: ButtonTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<RemoteActivity> getActivityTestRule() { return remoteActivityActivityTestRule; }
Example #19
Source File: MusicActivityTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<MusicActivity> getActivityTestRule() { return musicActivityActivityTestRule; }
Example #20
Source File: RestoreSearchQueryViewPagerTest.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<MusicActivity> getActivityTestRule() { return mActivityRule; }
Example #21
Source File: SlideUpPanelTests.java From Kore with Apache License 2.0 | 4 votes |
@Override protected ActivityTestRule<MusicActivity> getActivityTestRule() { return musicActivityActivityTestRule; }
Example #22
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 4 votes |
public static MaterialDatePicker<Pair<Long, Long>> showRangePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule, CalendarConstraints calendarConstraints) { return showRangePicker(activityTestRule, 0, calendarConstraints); }
Example #23
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 4 votes |
public static MaterialDatePicker<Pair<Long, Long>> showRangePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule) { return showRangePicker(activityTestRule, 0); }
Example #24
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 4 votes |
public static MaterialDatePicker<Long> showDatePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule, CalendarConstraints calendarConstraints) { return showDatePicker(activityTestRule, 0, calendarConstraints); }
Example #25
Source File: MaterialDatePickerTestUtils.java From material-components-android with Apache License 2.0 | 4 votes |
public static MaterialDatePicker<Long> showDatePicker( ActivityTestRule<? extends AppCompatActivity> activityTestRule) { return showDatePicker(activityTestRule, 0); }
Example #26
Source File: StickyHeadersTestRobot.java From StickyHeaders with Apache License 2.0 | 4 votes |
StickyHeadersTestRobot(ActivityTestRule<MainActivity> activityRule) { this.activityRule = activityRule; }
Example #27
Source File: SampleScreen.java From LocaleChanger with Apache License 2.0 | 4 votes |
public SampleScreen(Class<? extends Activity> activityClass) { this.activityRule = new ActivityTestRule<>(activityClass, false, false); }
Example #28
Source File: BaseTest.java From adamant-android with GNU General Public License v3.0 | 4 votes |
public BaseTest() { activityRule = new ActivityTestRule<>(provideActivityClass(), true, false); }
Example #29
Source File: AbstractTestClass.java From Kore with Apache License 2.0 | votes |
abstract protected ActivityTestRule<T> getActivityTestRule();